📅  最后修改于: 2022-03-11 14:59:28.301000             🧑  作者: Mango
// React Cache for simple data fetching (not final API)
import {unstable_createResource} from 'react-cache';
// Tell React Cache how to fetch your data
const TodoResource = unstable_createResource(fetchTodo);
function Todo(props) {
// Suspends until the data is in the cache
const todo = TodoResource.read(props.id);
return {todo.title} ;
}
function App() {
return (
// Same Suspense component you already use for code splitting
// would be able to handle data fetching too.
}>
{/* Siblings fetch in parallel */}
);
}
// Other libraries like Apollo and Relay can also
// provide Suspense integrations with similar APIs.