2 ms·
Unless I'm missing something, you don't need all that just to have 'componentDidMount' eg: export const useMounted = (f) => { useEffect(f, []); }
by ArchReaper 7y ago
Unless I'm missing something, you don't need all that just to have 'componentDidMount' eg:
export const useMounted = (f) => {
useEffect(f, []);
}
Edit: originally:
export const useMounted = (f) => {
useEffect(() => {
f();
}, []);
}
- acemarke 7y agoAnd to code-golf it a bit further, it can just be: useEffect(f, [])
- atombender 7y agoAh, of course. The use of dependency lists in React is something I keep forgetting exist. Thanks.