2 ms·
I tried to make a library as a workaround with async treatment in React which I also don't like, but besides it being a library (already a -1) it also didn't al
by franciscop 7y ago
I tried to make a library as a workaround with async treatment in React which I also don't like, but besides it being a library (already a -1) it also didn't allow you to have Hooks inside these async components, which was a showstopper for me. But still a fun experiment! This is how it worked:
// Books.js
import React from 'react';
import pray from 'pray';
// Wrap the async component in pray:
export default pray(async () => {
const books = await fetch('/books').then(res => res.json());
return (
<ul>
{books.map(book => <li>{book.title}</li>)}
</ul>
)
});
Would love to see good support for Async in React without the complexity that Suspense seems like it's going to bring.