Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 332x | import * as React from "react";
import { doNothing } from "remeda";
import {
getStoreStatesFromValues,
getStoreValuesFromInitialValues,
} from "~app/utils/store-data";
import type { StoreStates, StoreValues } from "~app/utils/store-data";
// The data above + data we add on each render
type StoreData = {
values?: StoreValues;
// Without this timestamp relative dates might differ on server and client
// (e.g. "1 second ago" and "2 seconds ago")
// which will cause hydration mismatch warning
nowTimestamp: Temporal.ZonedDateTime;
};
// The data above + flag of whether it's first render
export type StoreDataContextType = Omit<StoreData, keyof StoreValues> & {
isFirstRender: boolean;
} & StoreStates;
export const StoreDataContext = React.createContext<StoreDataContextType>({
...getStoreStatesFromValues(
getStoreValuesFromInitialValues(),
doNothing,
doNothing,
),
nowTimestamp: Temporal.Now.zonedDateTimeISO(),
isFirstRender: true,
});
|