General React Knowledge:
render()
, componentDidMount()
, etc. They can hold and manage local component state.useEffect()
.Component Lifecycle:
componentDidMount()
componentDidUpdate()
componentWillUnmount()
. They are useful for managing side effects, fetching data, and updating the UI in response to changes in state or props.useEffect
is a hook used in functional components to perform side effects in a way that's similar to lifecycle methods. It takes a function and runs it after the component has rendered. It's used for tasks like data fetching, setting up subscriptions, or manually changing the DOM.componentDidMount
is a lifecycle method in class components that runs once after the component has mounted. useEffect
with an empty dependency array in functional components achieves the same behavior; it runs the provided function once after the initial render when the component is mounted.
However, useEffect runs on runs after the paint has been committed to the screen as opposed to before. This means you would get a flicker if you needed to read from the DOM, then synchronously set state to make new UI.
useLayoutEffect
was designed to have the same timing as componentDidMount
State Management:
What is the purpose of the useState
hook? Provide an example of how to use it.
useState
is a hook used for managing component state in functional components. It returns an array with the current state value and a function to update it. Here's an example:
const [count, setCount] = useState(0);
What is Redux, and when would you use it in a React application?
How does data flow in a Redux application?
Describe the differences between local component state and Redux state.
useState
or this.state
in class components.What is the difference between Redux and context api?
/users/:id
, :id
is a route parameter, and the value can be accessed in the component associated with the route.Give an example for routing
Routing: