EduardS
EduardS
RReactiflux
Created by EduardS on 2/8/2023 in #react-forum
How to avoid calling hook conditionally here?
I have this data coming from validateData that return the rawData if valid otherwise null. I then check if data exists and return early otherwise. After that I use useCustomHook that depends on that data but because I returned early I get a warning that hook is called conditionally. How can I avoid this issue?
const MyComponent: FC<Props> = ({ rawData }) => {
const data = validateData(rawData);
if (!data) return null;

const someOtherData = useCustomHook(data.something);

return <div>{data.something}</div>;
};

export default MyComponent;
const MyComponent: FC<Props> = ({ rawData }) => {
const data = validateData(rawData);
if (!data) return null;

const someOtherData = useCustomHook(data.something);

return <div>{data.something}</div>;
};

export default MyComponent;
4 replies
RReactiflux
Created by EduardS on 1/31/2023 in #react-forum
Is a function that calls custom hooks also a custom hook?
Let's say I have a custom hook useLocaleStorage implemented with useState and useEffect then it is considered a hook because it uses built-in hooks. If then I create a function getTheme and I use useLocalStorage inside it then is getTheme considered a custom hook because the useLocaleStorage itself uses built-in hooks?
5 replies