R
Reactiflux

How to avoid calling hook conditionally here?

How to avoid calling hook conditionally here?

EEduardS2/8/2023
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;
Solution:
Message Not Public
Sign In & Join Server To View
Jump to solution
UUUnknown User2/8/2023
3 Messages Not Public
Sign In & Join Server To View

Looking for more? Join the community!

R
Reactiflux

How to avoid calling hook conditionally here?

Join Server