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

Function deletePath

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

Source from the content-addressed store, hash-verified

7247 }
7248
7249 function deletePath(
7250 type: 'context' | 'hooks' | 'props' | 'state',
7251 id: number,
7252 hookID: ?number,
7253 path: Array<string | number>,
7254 ): void {
7255 const devtoolsInstance = idToDevToolsInstanceMap.get(id);
7256 if (devtoolsInstance === undefined) {
7257 console.warn(`Could not find DevToolsInstance with id "${id}"`);
7258 return;
7259 }
7260 if (devtoolsInstance.kind !== FIBER_INSTANCE) {
7261 // TODO: Handle VirtualInstance.
7262 return;
7263 }
7264 const fiber = devtoolsInstance.data;
7265 if (fiber !== null) {
7266 const instance = fiber.stateNode;
7267
7268 switch (type) {
7269 case 'context':
7270 // To simplify hydration and display of primitive context values (e.g. number, string)
7271 // the inspectElement() method wraps context in a {value: ...} object.
7272 // We need to remove the first part of the path (the "value") before continuing.
7273 path = path.slice(1);
7274
7275 switch (fiber.tag) {
7276 case ClassComponent:
7277 if (path.length === 0) {
7278 // Simple context value (noop)
7279 } else {
7280 deletePathInObject(instance.context, path);
7281 }
7282 instance.forceUpdate();
7283 break;
7284 case FunctionComponent:
7285 // Function components using legacy context are not editable
7286 // because there's no instance on which to create a cloned, mutated context.
7287 break;
7288 }
7289 break;
7290 case 'hooks':
7291 if (typeof overrideHookStateDeletePath === 'function') {
7292 overrideHookStateDeletePath(fiber, ((hookID: any): number), path);
7293 }
7294 break;
7295 case 'props':
7296 if (instance === null) {
7297 if (typeof overridePropsDeletePath === 'function') {
7298 overridePropsDeletePath(fiber, path);
7299 }
7300 } else {
7301 fiber.pendingProps = copyWithDelete(instance.props, path);
7302 instance.forceUpdate();
7303 }
7304 break;
7305 case 'state':
7306 deletePathInObject(instance.state, path);

Callers

nothing calls this directly

Calls 3

deletePathInObjectFunction · 0.90
copyWithDeleteFunction · 0.90
getMethod · 0.65

Tested by

no test coverage detected