react-data-fetching
react-data-fetching copied to clipboard
Enable to pass in a side-effect
Opening an issue for documentation purposes. A PR covering this issue will follow.
Sorry @CharlesMangwa for delaying this for some time now.
Enable to pass in a callback that react-data-fetch
either runs on componentDidMount
or via passing down a run
function f.e., enabling to define when the fetch is run in user land.
This should solve the following issues:
- Being able to run multiple fetches serially or in parallel
- Enable to delay or re-run a fetch when needed
- Best case is implementing this in a fashion where we can run
Tasks
orPromises
, leaving the actual implementation to user land.
The following is not the actual implementation, but an initial idea.
const dataFetch = () => {
return fetch(SOME_URL_ENDPOINT)
.then(response => response.json());
}
export default class App extends Component {
render() {
return (
<Fetch
loader={<Loader/>} // Replace this with your lovely handcrafted loader
run={dataFetch}
>
{({ data, run /* can also be passed down and used inside a class component f.e. */ }) => (
<div>
<h1>Username</h1>
<p>{data.name}</p>
</div>
)}
</Fetch>
)
}
}
Hey @busypeoples! Thanks for taking the time to write this down! Since you've already sent your PR, let's continue the discussion there! #22
Sorry, misclicked!