MCPcopy
hub / github.com/react/react / useEditableValue

Function useEditableValue

packages/react-devtools-shared/src/devtools/views/hooks.js:82–112  ·  view source on GitHub ↗
(
  externalValue: any,
)

Source from the content-addressed store, hash-verified

80
81// Convenience hook for working with an editable value that is validated via JSON.parse.
82export function useEditableValue(
83 externalValue: any,
84): [UseEditableValueState, UseEditableValueDispatch] {
85 const [state, dispatch] = useReducer<
86 UseEditableValueState,
87 UseEditableValueState,
88 UseEditableValueAction,
89 >(useEditableValueReducer, {
90 editableValue: smartStringify(externalValue),
91 externalValue,
92 hasPendingChanges: false,
93 isValid: true,
94 parsedValue: externalValue,
95 });
96 if (!Object.is(state.externalValue, externalValue)) {
97 if (!state.hasPendingChanges) {
98 dispatch({
99 type: 'RESET',
100 externalValue,
101 });
102 } else {
103 dispatch({
104 type: 'UPDATE',
105 editableValue: state.editableValue,
106 externalValue,
107 });
108 }
109 }
110
111 return [state, dispatch];
112}
113
114export function useIsOverflowing(
115 containerRef: {current: HTMLDivElement | null, ...},

Callers 2

EditableValue.jsFile · 0.90
ExampleFunction · 0.85

Calls 3

useReducerFunction · 0.90
smartStringifyFunction · 0.90
dispatchFunction · 0.50

Tested by 1

ExampleFunction · 0.68