Skip to content
Advertisement

Tag: react-hooks

Why can’t `useCallback` always return the same ref

I don’t understand why useCallback always returns a new ref each time one of the deps is updated. It results in many re-render that React.memo() could have avoided. What is, if any, the problem with this implementation of useCallback? Using this instead of the built-in implementation sure has a significant positive impact on performance. Own conclusion: There is no reason

Can’t set state in js react-native

Getting error while trying to setState in React Native. Code Error TypeError: undefined is not an object (evaluating ‘_this.setState’) Answer useState Hook Functional components don’t have access to setState method but useState hook. useState hook works by defining the name of value, e.g. foo followed by it’s setter. It’s a convention to name the setter with the same name as

Passing a component to the useState() hook

I’m trying to make a system where my App component’s state stores another component, which it will render. Any component should be able to update this state, forcing the App component to re-render. I know how to make the state accessible by any component, but I’m having some issues with rendering the component in App’s state. When I try running

Advertisement