📜  React Cache 用于简单的数据获取(不是最终的 API) - 任何代码示例

📅  最后修改于: 2022-03-11 14:59:28.301000             🧑  作者: Mango

代码示例1
// 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.