Is there any reliable and readable naming standard as it comes to naming the outputs of the useReducer hook? What are the best practices, that make the further component's logic more understandable?
Naming the output of the useState is very intuitive and usually it comes down to:
const [value, setValue] = useState(0);
But I don't find it so obvious as it comes to the useReducer hook. In all the examples I have found, the most common approach is:
const [value, dispatch] = useReducer(valueReducer, 0);
However it doesn't make sense when there is more than one reducer used within the component.
The one could simply use:
const [value, dispatchValue] = useReducer(valueReducer, 0);
const [count, dispatchCount] = useReducer(countReducer, 0);
But this seems to not be self-explanatory on what the reducer functions actually do (in contrast to setValue which, as the name suggests, sets the value).
Naming these by their action names, for example:
const [value, incrementValue] = useReducer(valueReducer, 0);
const [count, multiplyCount] = useReducer(countReducer, 0);
Seems to be better but these on the other hand don't inform strictly that we use the dispatch/reducer hook anymore.
Instead of using reducerX, reducerY you better use the proper naming convention for this:
And also for the reducer function name better to use setValue instead of incrementValue
follow same for the other functions and variables.