Skip to content

[Feature]: Transform useState/useEffect of ReactJS to createSignal/onCleanup of SolidJS. #1

@trivikr

Description

@trivikr

Input code

import React, { useState, useEffect } from "react";
import { render } from "react-dom";

const CountingComponent = () => {
  const [count, setCount] = useState(0);
  useEffect(() => {
    const interval = setInterval(() => setCount(count + 1), 1000);
    return () => {
      clearInterval(interval);
    };
  }, []);
  return <div>Count value is {count}</div>;
};

render(() => <CountingComponent />, document.getElementById("app"));

Expected Output

import { createSignal, onCleanup, onMount } 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"));

Additional context

Example transform to convert useState/useEffect of ReactJS to createSignal/onCleanup of SolidJS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions