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

Function escape

packages/react/src/ReactChildren.js:39–51  ·  view source on GitHub ↗

* Escape and wrap key so it is safe to use as a reactid * * @param {string} key to be escaped. * @return {string} the escaped key.

(key: string)

Source from the content-addressed store, hash-verified

37 * @return {string} the escaped key.
38 */
39function escape(key: string): string {
40 const escapeRegex = /[=:]/g;
41 const escaperLookup = {
42 '=': '=0',
43 ':': '=2',
44 };
45 const escapedString = key.replace(escapeRegex, function (match) {
46 // $FlowFixMe[invalid-computed-prop]
47 return escaperLookup[match];
48 });
49
50 return '$' + escapedString;
51}
52
53/**
54 * TODO: Test that a single child and an array with one item have the same key

Callers 2

getElementKeyFunction · 0.85
makeTestCaseErrorFunction · 0.85

Calls

no outgoing calls

Tested by 1

makeTestCaseErrorFunction · 0.68