В настоящее время вы можете сделать что-то вроде этого:
class MyTableComponent {
state = {
loaded: false
}
componentDidMount() {
Promise.all([this.fetchColumn1(), this.fetchColumn2(), this.fetchColumn3()])
.then(([column1, column2, column3]) => {
// Do whatever you want with columns
this.setState({loaded: true, columns: {column1, column2, column3}})
});
}
render() {
// render nothing until everything is loaded (You can replace it with loading state
if(!this.state.loaded) return null;
else return <Table columns={this.state.columns} />
}
В будущем, с помощью response-cache, можно будет выполнять ту же работу очень аккуратно
const App = (props) => {
return (
<Suspense fallback={<p>Loading</p>}
<MyTable />
</Suspense>
)
}
const getColumn1 = () => {...}
const getColumn2 = () => {...}
const getColumn3 = () => {...}
const getColumns = () => Promise.all([getColumn1, getColumn2, getColumn3])
const columnsResource = createResource(getColumns)
const MyTableComponent = (props) => {
let [column1, column2, column3] = columnsResource.read();
// Columns will be fetched at this point, unless this line will now execute and nearest parrent suspense fallback will get rendered
return <Table columns={{column1, column2, column3}} />
}