MCPcopy
hub / github.com/preactjs/preact / createStatefulNullable

Function createStatefulNullable

test/browser/placeholders.test.jsx:29–55  ·  view source on GitHub ↗

* @param {string} name * @returns {[import('preact').ComponentClass, import('preact').RefObject<{ toggle(): void }>]}

(name)

Source from the content-addressed store, hash-verified

27 * @returns {[import('preact').ComponentClass, import('preact').RefObject<{ toggle(): void }>]}
28 */
29 function createStatefulNullable(name) {
30 let ref = createRef();
31 class Nullable extends Component {
32 constructor(props) {
33 super(props);
34 this.state = { show: props.initialShow || true };
35 ref.current = this;
36 }
37 toggle() {
38 this.setState({ show: !this.state.show });
39 }
40 componentDidUpdate() {
41 ops.push(`Update ${name}`);
42 }
43 componentDidMount() {
44 ops.push(`Mount ${name}`);
45 }
46 componentWillUnmount() {
47 ops.push(`Unmount ${name}`);
48 }
49 render() {
50 return this.state.show ? <div>{name}</div> : null;
51 }
52 }
53
54 return [Nullable, ref];
55 }
56
57 let resetAppendChild;
58 let resetInsertBefore;

Callers 1

Calls 1

createRefFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…