In 2023, Solid JS is poised to be the next big frontend framework. Its underlying fundamentals are fundamentally different from React's. This talk will expose my learnings as I have approached Solid from the perspective of a React developer.
re-renders to Virtual DOM every time data changes, and performs a diff to know which DOM elements to update is a compiled template language that remembers which DOM elements depend on which state
=> { const [count, setCount] = createSignal(0); setInterval(() => { setCount((previous) => previous + 1); }); onCleanup(() => clearInterval(interval)); const doubleCount = count() * 2; return ( <div> <h1>{doubleCount}</h1> </div> ); }; 1. Code before return happens only once! 2. JSX should never output a value that's not a signal (because otherwise it would never update) FOOTGUN #3: Only use signals in JSX. Never "get" their value before the JSX.
most dangerous hook in React – Erik Rasmussen @erikras probably plagiarizing David "Khourshid" 🎹 @davidkpiano probably plagiarizing Dan Abramov @dan_abramov
(props) => { const expensiveResult = useMemo( () = expensiveCalculation(props.value), [props.value] ); return ( <div> <h1> The result is: {expensiveResult} </h1> </div> ); }; useMemo export const Result = (props) => { const expensiveResult = expensiveCalculation(props.value); return ( <div> <h1> The result is: {expensiveResult} </h1> </div> ); }; FOOTGUN #3: Only use signals in JSX. Never "get" their value before the JSX.
Batched updates with batch() • Directives with use: props • Google "solid fi nal form" Solid Less Familiar <input name="firstName" placeholder="First Name" use:field />;
getter functions! 2. The Component function is called only once! 3. Only call signal getters in JSX (or other derived signals). Never call getter before return. 4. Never destructure props! 5. The Component function is called only once! 6. The Component function is called only once! <div>{value}</div> <div>{value()}</div> ❌ ✅