MCPcopy Index your code
hub / github.com/react/react / renamePath

Function renamePath

packages/react-devtools-shared/src/backend/fiber/renderer.js:7313–7386  ·  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

7311 }
7312
7313 function renamePath(
7314 type: 'context' | 'hooks' | 'props' | 'state',
7315 id: number,
7316 hookID: ?number,
7317 oldPath: Array<string | number>,
7318 newPath: Array<string | number>,
7319 ): void {
7320 const devtoolsInstance = idToDevToolsInstanceMap.get(id);
7321 if (devtoolsInstance === undefined) {
7322 console.warn(`Could not find DevToolsInstance with id "${id}"`);
7323 return;
7324 }
7325 if (devtoolsInstance.kind !== FIBER_INSTANCE) {
7326 // TODO: Handle VirtualInstance.
7327 return;
7328 }
7329 const fiber = devtoolsInstance.data;
7330 if (fiber !== null) {
7331 const instance = fiber.stateNode;
7332
7333 switch (type) {
7334 case 'context':
7335 // To simplify hydration and display of primitive context values (e.g. number, string)
7336 // the inspectElement() method wraps context in a {value: ...} object.
7337 // We need to remove the first part of the path (the "value") before continuing.
7338 oldPath = oldPath.slice(1);
7339 newPath = newPath.slice(1);
7340
7341 switch (fiber.tag) {
7342 case ClassComponent:
7343 if (oldPath.length === 0) {
7344 // Simple context value (noop)
7345 } else {
7346 renamePathInObject(instance.context, oldPath, newPath);
7347 }
7348 instance.forceUpdate();
7349 break;
7350 case FunctionComponent:
7351 // Function components using legacy context are not editable
7352 // because there's no instance on which to create a cloned, mutated context.
7353 break;
7354 }
7355 break;
7356 case 'hooks':
7357 if (typeof overrideHookStateRenamePath === 'function') {
7358 overrideHookStateRenamePath(
7359 fiber,
7360 ((hookID: any): number),
7361 oldPath,
7362 newPath,
7363 );
7364 }
7365 break;
7366 case 'props':
7367 if (instance === null) {
7368 if (typeof overridePropsRenamePath === 'function') {
7369 overridePropsRenamePath(fiber, oldPath, newPath);
7370 }

Callers

nothing calls this directly

Calls 3

renamePathInObjectFunction · 0.90
copyWithRenameFunction · 0.90
getMethod · 0.65

Tested by

no test coverage detected