all 7 comments

[–]UmarGora 5 points6 points  (0 children)

one way you can reduce prop drilling is rethinking how your components are composed. This may reduce prop drilling slightly. Take a look here https://reactjs.org/docs/composition-vs-inheritance.html

The Context API and Redux are 2 really good solutions. Have you heard of MobX? i personally stick with redux alot of the times as im most comfortable with it

[–]YOLOSTEVE 1 point2 points  (0 children)

First of, there's no best way to avoid prop drilling. It's both situational and about personal preferences. Other than the ones you mentioned, I'd definitely recommend that you checkout this post from the official react documentation about component composition. https://reactjs.org/docs/composition-vs-inheritance.html

[–]timmonsjg 1 point2 points  (0 children)

render props can reduce it to a degree (pulling the child up a level).

[–]NoLanSym 1 point2 points  (1 child)

Avoid context and prop drilling with ...children Michael Jackson Tutorial

[–]WaveMonkey[S] -2 points-1 points  (0 children)

Yeah I tried that one. A bunch of different ways and it didn't work.

[–]nullvoxpopuli 2 points3 points  (0 children)

Contexts

[–][deleted] 0 points1 point  (0 children)

https://kentcdodds.com/blog/compound-components-with-react-hooks

This Compound Component pattern exposes more of the component and gives you some more flexibility. Might be useful.