💡🧵 Props drilling❓
In react when you have a tree of a components and want to pass the data to the last component, you have to pass props through every component in tree and re-render all components on change. this is problem called as props drilling.

#reactjs #100DaysOfCode
this problem is like having a box within a box within a box. when you want to change things in the inner most box you have to open all the outer boxes to reach there every time. that's the case of props drilling, that you have to pass the props and re-render components.
To avoid this problem there's a solution. 🥁
Define the data globaly and then access it within the components you want and re-render the only components consuming data.
how to do that?
1. createContext
2. Provide context
3. Consume context
createContext is a built-in function in React, returns the Context component.
const Context = React.cretaeComponent("defaultVal")
default value can be provided and it's optional.
Now just export this Context component as
export default Context
Context need to be provided by some top component and then it will be consumed by the components no matter how many.
Context value can also be accessed by the useContext hook which takes Context as an argument.
for more read an article dmitripavlutin.com/react-context-… from @panzerdp

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Akram Narejo

Akram Narejo Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @akramnarejo

3 Oct
2/100 days of learning React.
export default vs named components in react.
In react view is built with components. components are exported before importing them.
Two way we export them either as default or named.
know more 👇🧵

#reactjs #javascript #100DaysOfCode
1. default
default is used when we export single component and considered default and while importing its name doesn't matter.

Compo = () => { return <p>hello, world</p> }
export default Compo

Import with other name won't mind.
import X from './Compo'
2. Named
we export named when we hav multiple.
& they require d same name while importing within {}.

export Comp1 = () => { return <p>Hello</p> }
export Comp2 = () => { return <p>World</p> }

Importing...
import {Comp1,Comp2} from './Compo'

while rendering wrap them with div.
Read 4 tweets
5 Aug
How to write ✍️ your notes 🗒, blog r even your github repositories with the markdown markup lang.
Let’s learn d following:
• headings
• text styling
• links
• syntax
• paragraphs
• lists
• tables
Follow d thread 🧵 2 read them 👇
#DEVCommunity #100DaysOfCode #markdown
1️⃣ Headings
For headings just insert the # before heading. And the numbers of # defines the heading number. Image
2️⃣ Text styling
To make bold use **text**
To make italic use * text * or _text_
For both use **_text_** Image
Read 12 tweets
29 Jul
Explaining Loop 🔁
1.
Loop is the fundamental building block of programming, used to repeat or iterate the fixed number of steps.
Loop saves the time and labour.

Thread 🧵

#100DaysOfCode #DEVCommunity #javascript #programming #loop
2. Real time example
Suppose you are donating $100 to each one of the 50 homeless.
For that you will keep count of people who are you done with.
So, 3 things we r doing:
• setting condition to 50
• counting ( increment )
• donating
3.
There are many ways out there to implement loop in programming:
• foor loop
• while loop
• forEach
• do while
and many, you can also develop your own.
Read 8 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(