diff --git a/src/lib/externalState.ts b/src/lib/externalState.ts index c9ccccc..25fac7f 100644 --- a/src/lib/externalState.ts +++ b/src/lib/externalState.ts @@ -31,13 +31,14 @@ const createExternalStateHook = (externalState: ExternalState) => { parse: (value) => value as T, }, ) { - const state = externalState.hasValue(key) - ? parser.parse(externalState.getValue(key)) - : defaultValue - const [_state, _setState] = useState(state) + const [_state, _setState] = useState(() => + externalState.hasValue(key) + ? parser.parse(externalState.getValue(key)) + : defaultValue, + ) return [ - state, + _state, (newValue: ValueOrReducer) => { _setState((prev) => { const value: T =