|
|
|
|
|
by satvikpendem
1207 days ago
|
|
I don't really understand why people like signals again. I used a signals-like reactive programming model in VueJS a while ago and hated that you could never be sure exactly where things were being changed. Thankfully it seems that the React creators and maintainers are not hopping on the signals train and are instead adamant about unidirectional dataflow with explicit mapping of state to UI, which, as has been the reason for why React had been invented in the first place, makes reasoning about the application much easier [0][1]. This is a good thread about their drawbacks [2]. Apparently, both the below examples actually do different things: function One(props) {
const doubleCount = props.count * 2;
return <div>Count: {doubleCount}</div>
}
function Two(props) {
return <div>Count: {props.count * 2}</div>
}
Like the tweeter says, signals are mutable state. I'll stick with unidirectional data flow in React.[0] https://twitter.com/jordwalke/status/1629663133039214593 [1] https://twitter.com/dan_abramov/status/1629539600489119744 [2] https://twitter.com/devongovett/status/1629540226589663233 |
|
1. The function is called only once at component construction, and never again. Unlike React, it is _not_ called for every render.
2. Every expression in `{}` is compiled to a thunk function - not to a direct JS expression.
For example, the expression
compiles to Another interesting bit - as the article above rightfully points out, `useState` and `useMemo` are signals. The main difference is that you have to track and specify your dependencies manually, whereas Solid auto-tracks dependencies based on their usage while the computation runs.