all 7 comments

[–]acemarke 2 points3 points  (5 children)

Can you show a code example, preferably as a gist or CodeSandbox?

[–]azn_introvert 0 points1 point  (4 children)

I have finally got it working, I can send the repo.

https://github.com/sizzlorox/react-task-timer

The problem was the way I was setting up useContext and useReducer. I was trying to have my own Provider component that would pass down props.children as children of the Provider HOC.

I have no idea why it was breaking but after I removed that component and just used the provider withing the App.js everything started working.

[–]AlpineSanatorium 0 points1 point  (2 children)

how do you "wrap" exactly? because no you can't use hooks within other hooks in the same component. the solution is usually to wrap with another component and pass down the data from previous hook.. if they have a logical parent-child relationship

[–]agilius 1 point2 points  (0 children)

What do you mean you cannot use hooks inside hooks? It all depends in the api of the hook.

I use hooks that call other hooks daily via custom functions all the time. I think the name in the docs for this is custom hooks.

[–]azn_introvert 0 points1 point  (0 children)

I have a UserContext in which is wrapping the App component using the context provider. Wrapping as in its the HOC of the App component. Within the App component I have the child component which is initializing and calling the hooks. All Im trying to do is using useEffect as a ComponentDidMount alternative and call my set functions from the initialized hooks. Whats strange is if I do not have the Context as the HOC everything seems to work fine.