locklock123
locklock123

Reputation: 241

react native callback dispatch which is right?

which way is correct ?

way 1:

  const dispatch = useDispatch();

  const add = useCallback(() => {

  }, [dispatch]);

way2:

  const dispatch = useCallback(() => {
    return useDispatch();
  }, []);

  const add = useCallback(() => {

  }, [dispatch]);

................................................................................................................................................................................

Upvotes: 0

Views: 101

Answers (1)

Keilath
Keilath

Reputation: 456

The first way for sure: hooks can only be called in the context of a functional component, and not in the body of another hook call (hence you cannot nest useDispatch inside useCallback)

Upvotes: 1

Related Questions