High Ordered Components are used in traditional Redux via connect
. Hooks do not usually incorporate HOCs.
Components maybe designed like this if components share certain behaviours in way that makes them connection in some form, for example props and state
.
Usually in HOCs it is the parent component in which where the data is kept. For example in tradiitonal Redux, the page will usually connect
to get access to the data via the store. The data is then passed down via props
.
Here is an example of useState
in React hooks.
const [character, setCharacter] = useState({})
useEffect(() => {
axios.get(`https://swapi.co/api/people/`)
.then(res => {setCharacter(res.data)})
}, [])
The hook useEffect
behaves similarly to componentDidMount
. This hook enables you to deal with side effects and is executed after every render cycle. The second argument of the empty array controls if the function should be executed, for example like a change of value within the array.