You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
consttext= () =>`Hello, ${props.name}!`; // `text` now acts like a signal
46
46
47
-
return<span class="greeting">{text()}</span>;
48
-
}
47
+
return<span class="greeting">{text()}</span>;
48
+
}
49
49
```
50
50
51
-
<details>
52
-
<summary>Why does this work?</summary>
51
+
<details>
52
+
<summary>Why does this work?</summary>
53
53
54
-
Solid's compiler transforms expressions in JSX; it wraps them in a function, and creates an effect
55
-
to track when they've changed in order to update the UI. So `<span>{text()}</span>` becomes
56
-
`<span>{() => text()}</span>`, and `<span>{props.name}</span>` becomes `<span>{() => props.name}</span>`. The `props.name` access works just like a signal call because `.name` is a
57
-
getter function under the hood; a function call in both cases. It's important that the accesses
58
-
happen in the JSX for the tracking to work.
59
-
</details>
54
+
Solid's compiler transforms expressions in JSX; it wraps them in a function, and creates an effect
55
+
to track when they've changed in order to update the UI. So `<span>{text()}</span>` becomes
56
+
`<span>{() => text()}</span>`, and `<span>{props.name}</span>` becomes `<span>{() => props.name}</span>`. The `props.name` access works just like a signal call because `.name` is a
57
+
getter function under the hood; a function call in both cases. It's important that the accesses
// The reactive variable 'props.count' should be used within JSX, a tracked scope (like
68
+
// createEffect), or inside an event handler function, or else changes will be ignored.
69
+
}
70
+
```
71
71
72
-
Even when using a prop to initialize a signal, you'll still get the same warning as described
73
-
above. This code ignores any changes to `props.count`, instead of reacting to those changes.
72
+
Even when using a prop to initialize a signal, you'll still get the same warning as described
73
+
above. This code ignores any changes to `props.count`, instead of reacting to those changes.
74
74
75
-
> React developers: this is equivalent to `const [count, setCount] = useState(props.count)`.
75
+
> React developers: this is equivalent to `const [count, setCount] = useState(props.count)`.
76
76
77
-
Though it's often better to use props directly instead of creating new state from props, there are
78
-
cases where this pattern is what you want. You can safely ignore the rule when you are providing
79
-
an "initial" or "default" value to a component ("uncontrolled components" in React).
77
+
Though it's often better to use props directly instead of creating new state from props, there are
78
+
cases where this pattern is what you want. You can safely ignore the rule when you are providing
79
+
an "initial" or "default" value to a component ("uncontrolled components" in React).
80
80
81
-
That's why there's an escape hatch for this case; any props beginning with `initial` or `default`
82
-
won't trigger this warning. By using the `initial` or `default` prefix, you've shown that you
83
-
intend to ignore updates to that prop. If you can't or don't want to use the prefix, adding an `// eslint-disable-next-line` comment to disable the warning accomplishes the same thing.
81
+
That's why there's an escape hatch for this case; any props beginning with `initial` or `default`
82
+
won't trigger this warning. By using the `initial` or `default` prefix, you've shown that you
83
+
intend to ignore updates to that prop. If you can't or don't want to use the prefix, adding an `// eslint-disable-next-line` comment to disable the warning accomplishes the same thing.
0 commit comments