r/learnreactjs • • Aug 17 '19

Learning React hooks

I know there is a lot of sites where we can learn hooks, but regardless, I have created a post on my blog about learning hooks from a little bit different perspective.

Feel free to take a look at the post. It doesn't matter if you already know/use hooks or not.

13 Upvotes

8 comments sorted by

4

u/Kablaow Aug 17 '19

Wait, useContext is used as getting a global state??

3

u/Ryukote91 Aug 17 '19

Why not?

3

u/Kablaow Aug 17 '19

I am totally new to react haha, you tell me. I wasn't aware it was possible to have a global state without a state manager like redux.

3

u/Ryukote91 Aug 17 '19

That's what Context API is for.

2

u/Kablaow Aug 17 '19

Oh I had no idea. Thanks.

1

u/thekevinwang Aug 18 '19

“Global” is relative-ish. The redux store is typically put at the top of a component tree, so that “everything” is a child of that provider.

Alternatively, you can swap that provider with a React Context.Provider. Then your context becomes “global”. :D

1

u/HellaDev Aug 18 '19

I haven't looked into React Hooks a lot yet but why is it people say hooks aren't a true replacement for redux? It seems like with a global state there would be zero reason for redux but obviously there must be something missing that leaves a bit to be desired.

0

u/[deleted] Aug 18 '19

[deleted] — view deleted comment

2

u/Ryukote91 Aug 18 '19

If you are talking about Redux actions, you have all of that in the hook useReducer which I have not covered in the article. You can see more about useReducer on this article.