As a dev (who's in love with React), I need more of these shorts!!
1- i use function call On parent calling expect props by children 2- use Context 3- redux
It's so tough. C++ Java were easy back in our times!
I think that calling this child component Callback is not the best Idea, evenmore in an interview context. Because Callback is a concept and components should not be named as concepts. The sub component that takes a function as a prop could be named as <ColorNameInput updateColor={updateColor} /> in my opinion this is more obvious than Callback... As a recruiter I will also expect from candidate to be conscious of the naming aspect because this is often a negliged aspect. Of course you're right this question of props drilling up and down is important. :) My coment is only my opinion.
Another solution is just passing the setUIcolor into child and set the color in handleChange… :)
instead getColor, it should be setColor because you are setting and not getting.
why don't we use state lifting ?? we can create a function on the parent component to do all the stuff and pass it to the child component , and just use that in onChange event in the input
Make component controlled or uncontrolled, don’t mix it. And you will thank you to yourself in the future.
Thanks Sandip. It's really helpful . Want more shorts like this
Wow. So I just did that yesterday without knowing. It felt so normal and easy for me
That’s masterpiece, never thought about it . Thanks sir ❤
Wish you more of strength! For making react Interviewee's life easier
Context is the best thing to use for react state management. You would set the state in a provider file which will be used as a component to wrap your entire project (or everything it’s relevant to) and then you import what you need into the child components including values and functions
I fucking wish they asked me questions as easy as this
Sinple yet effective. You are smart.
You can directly use useRef in parent and send it to child through prop....and use ref in input box....you will get current value of box through ref in parent ryt??
Its not a callback function. You can refer it as a pointer at a function with arguments to be passed into
Thank you Sandip for the video 🙏
i love components. and i do this all the time, great now I know what its called thanks !
@ikevin127