Now with hooks, I've got the component's state split into more miniature states. This seemed better until I wanted to find out what state change caused a specific re-render.
How can one easily find out what state change caused a specific re-render?
If state updates need to be tracked for state management like accessing previous state values, this should be handled explicitly with custom hooks that wrap useState
.
As for debugging, React dev tools currently don't offer this functionality, although this information may be available through renderer undocumented API used in dev tools.
It's possible to add a breakpoint inside React dispatchAction
function and walk call stack up to know which state setter was called:
Or custom hook can be used instead of useState
to keep track of state updates:
const useDebuggableState = initialState => {
const [state, setState] = useState(initialState);
useMemo(() => {
'a line to add breakpoint';
}, [state]);
return [state, setState];
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With