MCPcopy
hub / github.com/facebook/react / renamePath

Function renamePath

packages/react-devtools-shared/src/backend/legacy/renderer.js:1007–1040  ·  view source on GitHub ↗
(
    type: 'context' | 'hooks' | 'props' | 'state',
    id: number,
    hookID: ?number,
    oldPath: Array<string | number>,
    newPath: Array<string | number>,
  )

Source from the content-addressed store, hash-verified

1005 }
1006
1007 function renamePath(
1008 type: 'context' | 'hooks' | 'props' | 'state',
1009 id: number,
1010 hookID: ?number,
1011 oldPath: Array<string | number>,
1012 newPath: Array<string | number>,
1013 ): void {
1014 const internalInstance = idToInternalInstanceMap.get(id);
1015 if (internalInstance != null) {
1016 const publicInstance = internalInstance._instance;
1017 if (publicInstance != null) {
1018 switch (type) {
1019 case 'context':
1020 renamePathInObject(publicInstance.context, oldPath, newPath);
1021 forceUpdate(publicInstance);
1022 break;
1023 case 'hooks':
1024 throw new Error('Hooks not supported by this renderer');
1025 case 'props':
1026 const element = internalInstance._currentElement;
1027 internalInstance._currentElement = {
1028 ...element,
1029 props: copyWithRename(element.props, oldPath, newPath),
1030 };
1031 forceUpdate(publicInstance);
1032 break;
1033 case 'state':
1034 renamePathInObject(publicInstance.state, oldPath, newPath);
1035 forceUpdate(publicInstance);
1036 break;
1037 }
1038 }
1039 }
1040 }
1041
1042 function overrideValueAtPath(
1043 type: 'context' | 'hooks' | 'props' | 'state',

Callers

nothing calls this directly

Calls 4

renamePathInObjectFunction · 0.90
forceUpdateFunction · 0.90
copyWithRenameFunction · 0.90
getMethod · 0.65

Tested by

no test coverage detected