Top "React-hooks" questions

Hooks is a new feature that allows developers to use state(s) and other React features without writing a class.

Correct way to create event handlers using hooks in React?

In a typical class-based React component, this is how I would create an event handler: class MyComponent extends Component { handleClick = () =&…

javascript reactjs jsx react-hooks
Definition for rule 'react-hooks/exhaustive-deps' was not found

I am getting the following eslint error after adding // eslint-disable-next-line react-hooks/exhaustive-deps in my code. 8:14 error Definition for rule 'react-hooks/…

javascript reactjs react-hooks eslint standardjs
What does it mean to 'move this variable directly inside useEffect' in this error message?

I am attempting to pass an object through props to a child component. The value is set in the useEffect …

reactjs react-hooks use-effect
how to set state array using react hooks

Thanks in advance. I have a state array as below. I need to add an item to state array, I …

reactjs react-native react-hooks setstate
How to setInterval for every 5 second render with React hook useEffect in React Native app?

I have React Native app and I get data from API by fetch. I created custom hook that get data …

javascript react-native setinterval react-hooks use-effect
Understanding the React Hooks 'exhaustive-deps' lint rule

I'm having a hard time understanding the 'exhaustive-deps' lint rule. I already read this post and this post but I …

reactjs react-hooks eslint
Cannot read property 'history' of undefined (useHistory hook of React Router 5)

I am using the new useHistory hook of React Router, which came out a few weeks ago. My React-router version …

reactjs react-router react-hooks react-router-dom react-context
useMemo vs. useEffect + useState

Are there any benefits in using useMemo (e.g. for an intensive function call) instead of using a combination of …

javascript reactjs typescript react-hooks
React useReducer: How to combine multiple reducers?

I'm not a Javascript expert so I wondered if anyone has an "elegant" way to combine multiple reducers to create …

javascript reactjs react-redux react-hooks reducers
What is the intention of using React's useCallback hook in place of useEffect?

I'm trying to understand what the use case is for using React's useCallback hook in place of the useEffect hook. …

javascript reactjs react-hooks