- Giving function components the ability to have internal state and trigger side effects, giving them the same capabilities as class components have had
- Reusing logic across components
I talked about the progress from mixins to HOCs to render props to hooks in a talk at ReactBoston last year [0], which had an example of tracking mouse coordinates using all four approaches. In that sense, yes, they do replace the other techniques as a way to reuse logic.
You call them inside of your function components, like this:
function MyComponent() {
const [counter, setCounter] = useState(0);
const {x, y} = useMousePosition();
// rest of the rendering logic here
}
- Giving function components the ability to have internal state and trigger side effects, giving them the same capabilities as class components have had
- Reusing logic across components
I talked about the progress from mixins to HOCs to render props to hooks in a talk at ReactBoston last year [0], which had an example of tracking mouse coordinates using all four approaches. In that sense, yes, they do replace the other techniques as a way to reuse logic.
You call them inside of your function components, like this:
[0] https://blog.isquaredsoftware.com/2019/09/presentation-hooks...