Linked Questions

3 votes
4 answers
15k views

Before React hooks, I would use componentDidUpdate(prevProps, prevState), and if I wanted to execute given code only when this.state.a had updated, I'd do if (prevState.a !== this.state.a) { <...&...
gkeenley's user avatar
  • 7,648
0 votes
2 answers
2k views

I have a parent component, that render one child component several time. This child component is used in many different components. I need to have an array in this child component that keeps all the ...
Beekman's user avatar
  • 13
208 votes
14 answers
293k views

I want my ReactJS app to notify a user when navigating away from a specific page. Specifically a popup message that reminds him/her to do an action: "Changes are saved, but not published yet. Do ...
Barry Staes's user avatar
  • 4,143
24 votes
5 answers
20k views

Currently useEffect is fired when just one of the dependencies have changed. How could I update it / use it to fire when all of the dependencies have changed?
Jack's user avatar
  • 3,067
16 votes
4 answers
7k views

I have a React component that fetches data using the useEffect hook like so: const cache = {key: "data-fetched-using-key"} function Config({key, options}) { const [data, setData] = useState(); ...
vis's user avatar
  • 504
7 votes
4 answers
11k views

I am looking for a way to perform more advanced comparison instead of the second parameter of the useEffect React hook. Specifically, I am looking for something more like this: useEffect( () => ...
Victor's user avatar
  • 14.7k
2 votes
4 answers
8k views

How do I use prevState with useEffect in a functional component? I was told to update class component to functional component and I'm stuck in the componentDidUpdate part where prevState was used ...
reactRookie's user avatar
7 votes
2 answers
3k views

I have recently written a table component using hooks , and every time page loads there is an API call to backend, so meanwhile there is a loading Spinner will be shown until there is an response from ...
jarivak's user avatar
  • 858
2 votes
2 answers
4k views

I'm trying to convert UNSAFE_componentWillReceiveProps into a hook. Below is the logic for using CWRP. UNSAFE_componentWillReceiveProps(nextProps){ if (this.props.val1 !== nextProps.val1 && ...
Faiyaz Shaikh's user avatar
4 votes
1 answer
5k views

I'm trying to use useDeferredValue hook in React 18 to defer updating a part of the UI based on a state variable. According to React documentation: During the initial render, the returned deferred ...
Pluto's user avatar
  • 5,165
2 votes
3 answers
2k views

I want to store the previous value in a variable and use it in a function. Let's say if the current value is 9, the previous value is supposed to be 8 (like one less). The problem is that console.log(...
Simon's user avatar
  • 47
2 votes
2 answers
4k views

I have a form composed of several input components. The form data is shared and shareable across these sibling components via a React context and the React hook useContext. I am stumbling on how to ...
Kwhitejr's user avatar
  • 2,316
0 votes
4 answers
3k views

How can we identify props changes in functional component?. Sample code here. Can you please help me to convert this componentDidUpdate method to functional componet using useEffect or any other way. ...
Lineesh Mb's user avatar
1 vote
3 answers
2k views

I will attempt to keep this brief, but I am not 100% sure of the correct method of achieving what I am aiming for. I have been thrown in the deep end with React with not much training, so I have most ...
mcclosa's user avatar
  • 1,505
4 votes
2 answers
1k views

I have a voice dictation custom hook, along with a separate custom hook that appends the dictation results to an object that stores "Note" values. If the user clicks save too early, there are still ...
Stephen A. Lizcano's user avatar

15 30 50 per page