-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using signals does not trigger re-render after updating the signal #120
Comments
@motss The problem you're running into is that you are setting your signal value to an object and then updating the properties of that object, this won't cause a render because those properties are not themselves signals. For the signal to update you want to have an assignment to the signal's |
@mikerob215 Do you mean const otpCodeSignal = signal<string>('');
...
<input name="code" value={otpCodeSignal} /> Doing the above will not result in a TypeScript error. How do I resolve this? |
The JSX TS errors are tracked here: #106 . It's a typing issue with TS, but passing a signal into it works regardless. |
Closing this issue, because like @mikerob215 noticed the provided example only tracks the whole state object. We didn't go with deep observability with signals, because it would end up with us having to wrap all built-in types ( Looking at state in the provided example it looks like you want to be able to react to both the - const state = signal<State>({ name: '', otpStatus: '' });
+ const state = { name: signal(''), otpStatus: signal('') }; |
|
this should be mentioned somewhere in the docs. |
you can use signal without any problems. ts: anyValue: Signal = this.state.anyValue; html: {{ anyValue() }} |
Description
I'm trying to experiment with signals in Preact and found out that sometimes updating the value does not always trigger re-render when it should in a component. I would like to know if I'm using signals the correct way.
This is a minimal reduced test case to demonstrate the problem. The basic behavior is as follows:
otpCode
, hitting Enter in theCode
input will trigger a countdown timer and you should seeResend in 00:10
otpCode
, hitting Enter will evaluatefakeValid
. WhenfakeValid
is true, there will be noResend in 00:10
andSend code
button, andCode
input will be in read-only mode.Expected behavior
Re-render should happen after updating signal value, e.g. updating
otpCode
andotpStatus
does not re-render.Actual behavior
Re-render does not always happen after updating signal value, e.g. updating
otpCode
andotpStatus
should re-render accordingly.The text was updated successfully, but these errors were encountered: