For further actions, you may consider blocking this person and/or reporting abuse
For further actions, you may consider blocking this person and/or reporting abuse
Vivek Alhat -
Pierre Chollet -
Pieces 🌟 -
Yuval -
Once suspended, himanshupal0001 will not be able to comment or publish posts until their suspension is removed.
Once unsuspended, himanshupal0001 will be able to comment and publish posts again.
Once unpublished, all posts by himanshupal0001 will become hidden and only accessible to themselves.
If himanshupal0001 is not suspended, they can still re-publish their posts from their dashboard.
Once unpublished, this post will become invisible to the public and only accessible to Himanshupal0001.
They can still re-publish the post if they are not suspended.
Thanks for keeping DEV Community safe. Here is what you can do to flag himanshupal0001:
Unflagging himanshupal0001 will restore default visibility to their posts.
Top comments (4)
Deep dive: How do React hooks really work?
Don't just read it.
Play with each example (which only requires vanilla JS - no React) until you fully understand how and why things work. Hopefully by the time you finish
// Example 4, revisited
you'll have the necessary Eureka moment of understanding what hooks are actually doing.It's function component, not functional - the allusion to functional programming is misplaced especially when hooks are involved.
A function component is just a render function (similar to the
render()
method on the class component).Now imagine that a component is used multiple times on the page. There is only one component (the function) but there are multiple component instances on the page (React's component (instance) tree), each one responsible for their particular part of the markup (ReactNodes, JSX) on the page.
Whenever React wants to update one of those parts it makes the "hooks environment" for that particular component instance current and then invokes the function component to render the necessary
ReactNode
s; the function component accesses the environment/data for the current component instance via hooks, so that it can render (and start effects) that are appropriate for the state of the current component instance.There is this old (2015) blog post by Dan Abramov React Components, Elements, and Instances that I found helpful. It's largely about class components but it's useful to understand the role that component instances play.
"Only components declared as classes have instances, and you never create them directly: React does that for you."
Even with class components the component instance is represented by the specific set of props and the state that is managed by React separately from the object that was created from the component class.
Before hooks function components were purely driven by the props as they were generated by the owner component.
With hooks function components get access to a full component instance but again it's React that sets up the instance which the component can initialize and then later update through the lifetime of the component instance.
Thanks for this. I will look into it.
Functional React components are like the old class component with a different syntax. They have life cycle hooks and support custom hooks. Most common life cycle hooks are useState, useEffect and useRef. React remembers the state of the life cycle hooks between renders so they can work the way React describes them.
Custom hooks are just like regular javascript functions with the exception that they can contain and run React's life cycle hooks. They will be called every time the component renders. Custom hooks are basically just a way for you to lift out code blocks from your React component and reuse it in other components.
I have some code examples in my post here where you can see in which order React invokes life cycle hooks and custom hooks.
Thanks for the explanation.