/
githubmr
/
facebook-react
Обзор
Документация
Войти
/
githubmr
/
facebook-react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
fixtures/ssr2/src/data.js
38 строк
1 KB
Andrew Clark
[Codemod] Update copyright header to Meta (#25315)
18 окт 2022, 18:19
Не верифицирован
18 окт 2022, 18:19
9cdf8a9
Код
Авторство
О чём код?
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import {createContext, useContext} from 'react'; // Note: this file does not demonstrate a real data fetching strategy. // We only use this to simulate data fetching happening on the server // while the cache is populated on the client. In a real app, you would // instead use a data fetching library or Server Components for this. const DataContext = createContext(null); export function DataProvider({children, data}) { return <DataContext.Provider value={data}>{children}</DataContext.Provider>; } // In a real implementation the data would be streamed with the HTML. // We haven't integrated this part yet, so we'll just use fake data. const fakeData = [ "Wait, it doesn't wait for React to load?", 'How does this even work?', 'I like marshmallows', ]; export function useData() { const ctx = useContext(DataContext); if (ctx !== null) { // This context is only provided on the server. // It is here to simulate a suspending data fetch. ctx.read(); } return fakeData; }