ReactJS Interview (QnA) Thread 🧵

👉 Part - 69

#reactjs #interview
1. What is a consumer?

A Consumer is a React component that subscribes to context changes. It requires a function as a child which receives current context value as argument and returns a react node.
The value argument passed to the function will be equal to the value prop of the closest Provider for this context above in the tree.
Lets take a simple example,
2. How do you solve performance corner cases while using context?

The context uses reference identity to determine when to re-render, there are some gotchas that could trigger unintentional renders in consumers when a provider’s parent re-renders.
For example, the code below will re-render all consumers every time the Provider re-renders because a new object is always created for value.
This can be solved by lifting up the value to the parent state,
3. What is the purpose of forward ref in HOCs?

Refs will not get passed through because the ref is not a prop. It is handled differently by React just like a key. If you add a ref to a HOC, the ref will refer to the outermost container component, not the wrapped component.
In this case, you can use Forward Ref API. For example, we can explicitly forward refs to the inner FancyButton component using the React.forwardRef API.
The below HOC logs all props,
Let's use this HOC to log all props that get passed to our “fancy button” component,
Now let's create a ref and pass it to FancyButton component. In this case, you can set focus to the button element.
That's all folks for today. Follow me @Shadabshs for more important and interesting updates related to web development

#reactjs #interview #javascript

• • •

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

Keep Current with Md Shadab Alam

Md Shadab Alam 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 @Shadabshs

26 Sep
ReactJS Interview (QnA) Thread 🧵

👉 Part - 70

#reactjs #interview Image
1. Is it ref argument available for all functions or class components?

Regular function or class components don’t receive the ref argument, and ref is not available in props either. The second ref argument only exists when you define a component with React.forwardRef call.
2. Why do you need additional care for component libraries while using forward refs?

When you start using forwardRef in a component library, you should treat it as a breaking change and release a new major version of your library.
Read 9 tweets
25 Sep
Best Github repositories for web developers:

🧵👇🏻
1. Node.js Best Practices
Node.js best practices list (August 2021) github.com/goldbergyoni/n…
2. HTML5 Boilerplate
A professional front-end template for building fast, robust, and adaptable web apps or sites.
github.com/h5bp/html5-boi…
Read 8 tweets
25 Sep
8 Awesome articles resources to understand new, Constructors, instanceof and Instances.

A Thread 🧵👇
📜 JavaScript For Beginners: the ‘new’ operator — Brandon Morelli

codeburst.io/javascript-for…
📜 Let’s demystify JavaScript’s ‘new’ keyword — Cynthia Lee

medium.freecodecamp.org/demystifying-j…
Read 10 tweets
24 Sep
Do you want to stand out in a job interview? Learn Git.

Git is an essential tool for developers. Every team is using some kind of version control system and Git is the most commonly used.

I collected for you a few tools to help you learn Git.

A Thread 🧵👇
1. Git and Git-flow cheat sheet.

Link: github.com/arslanbilal/gi…
2. Learn Git branching

An interactive Git visualization tool to educate and challenge!

Link: learngitbranching.js.org
Read 6 tweets
24 Sep
10 Awesome articles Resources to understand this, call , apply and bind

A Thread 🧵👇 Image
📜 Grokking call(), apply() and bind() methods in JavaScript — Aniket Kudale
levelup.gitconnected.com/grokking-call-…
📜 How-to: call() , apply() and bind() in JavaScript — Niladri Sekhar Dutta

codementor.io/niladrisekhard…
Read 10 tweets
24 Sep
ReactJS Interview (QnA) Thread 🧵

👉 Part - 68

#reactjs #interview Image
1 . What is the purpose of default value in context?
The defaultValue argument is only used when a component does not have a matching Provider above it in the tree. This can be helpful for testing components in isolation without wrapping them.
Below code snippet provides default theme value as Luna. Image
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!

:(