This is a higher order component ("HOC"). It's an advanced pattern used in React that let you reuse code logic, it can be summarized as a component factory. It improves isolation, interoperability and maintainability of your code base.
hoc-react-loader's purpose is to call a load
callback passed through the props
of a component only once (at componentWillMount
). This is convenient to load data from a backend for instance. The component shows a loading indicator when it's waiting for the props to be defined. The loading indicator can be changed easily.
- To see full documentation: click here
- Do you want a default LoadingIndicator and a default ErrorIndicator?, you can use @hoc-react-loader/full
- You want your bundle not being bloated?, you can use @hoc-react-loader/core
import React from 'react'
import loader from '@hoc-react-loader/core'
const Component = ({ data }) => <div>Component {JSON.stringify(data)}</div>
const load = props => console.log(props)
export default loader({ print: ['data'], load })(Component)
In this example load
will be called at first mount, then the wrapped Component
will be printed only if props.data
is truthy.
load
function can be the moment you ask for your API data.
You can test some examples here.
uni rakun is created by two passionate french developers.
Do you want to contact them ? Go to their website
Guillaume CRESPEL | Fabien JUIF |