Skip to content

Latest commit

 

History

History
18 lines (13 loc) · 643 Bytes

File metadata and controls

18 lines (13 loc) · 643 Bytes

solid-use/server-value

A primitive that allows to pass server-side values to client-side. This is useful to prevent potential hydration mismatches (e.g. inconsistent initial state).

useServerValue

import useServerValue from 'solid-use/server-value';

// This is the most common problem for SSR + hydration
// A function that isn't idempotent may cause hydration mismatches
// since there's no way to be consistent between the server
// and the client.
// Some example of this is `Math.random` and `Date.now`
const initialState = useServerValue(() => Math.random());

const [value, setValue] = createSignal(initialState);