mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: This diff breaks the RNTester app at runtime and it prevents us from cutting RN 0.69. Original commit changeset: a879787d8683 Original Phabricator Diff: D35435562 (https://github.com/facebook/react-native/commit/f4c4f446e4365c6cf7adf5db21d3d746b38aa3e2) ## Changelog [General][Fixed] - Revert change which breaks RNTester Reviewed By: cortinico, kacieb Differential Revision: D35936298 fbshipit-source-id: c4ec92002fde9c1de691bcda17ebc5d0747914f6
34 lines
802 B
JavaScript
34 lines
802 B
JavaScript
/**
|
|
* 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.
|
|
*
|
|
* @format
|
|
* @flow
|
|
*/
|
|
|
|
import * as React from 'react';
|
|
import {AsyncStorage} from 'react-native';
|
|
|
|
import type {RNTesterState} from '../types/RNTesterTypes';
|
|
|
|
export const useAsyncStorageReducer = (
|
|
reducer: Function,
|
|
initialState: RNTesterState,
|
|
storageKey: string,
|
|
): [RNTesterState, Function] => {
|
|
const [state, dispatch] = React.useReducer<Function, Object>(
|
|
reducer,
|
|
initialState,
|
|
);
|
|
|
|
React.useEffect(() => {
|
|
if (state !== initialState) {
|
|
AsyncStorage.setItem(storageKey, JSON.stringify(state));
|
|
}
|
|
}, [state, storageKey, initialState]);
|
|
|
|
return [state, dispatch];
|
|
};
|