-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Feature]: Transform useState/useEffect of ReactJS to createSignal/onCleanup of SolidJS. #1
Comments
It's also interesting if we can convert "unlisted dependencies" and transform them into const [count, setCount] = useState(0);
useEffect(() => {
console.log(count); // passively read count
}, []); into const [count, setCount] = createSignal(0);
createEffect(() => {
console.log(untrack(count)); // passively read count
}); |
I would actually expect the import { createSignal, onMount, onCleanup } from "solid-js";
import { render } from "solid-js/web";
const CountingComponent = () => {
const [count, setCount] = createSignal(0);
onMount(() => {
const interval = setInterval(() => setCount(count + 1), 1000);
onCleanup(() => clearInterval(interval));
});
return <div>Count value is {count()}</div>;
};
render(() => <CountingComponent />, document.getElementById("app")); |
Thanks, @N0tExisting! |
Well actually it doesn't have to |
I agree this would be cool. Simpler to implement though (much more "like React") would be to transform into [name, setName] = useState('');
[debug, setDebug] = useState(false);
useEffect(() => {
if (debug) console.log(`Hello ${name}!`);
}, [name]); → [name, setName] = createSignal('');
[debug, setDebug] = createSignal(false);
useEffect(on([name], () => {
if (debug()) console.log(`Hello ${name()}!`);
})); This seems like a natural first goal; then we can output nicer things when the list is empty or complete, or use |
Input code
Expected Output
Additional context
Example transform to convert useState/useEffect of ReactJS to createSignal/onCleanup of SolidJS.
The text was updated successfully, but these errors were encountered: