Skip to content
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

修复 NumberInput 渲染死循环的问题 #1994

Merged
merged 1 commit into from Dec 27, 2022

Conversation

cpylua
Copy link
Collaborator

@cpylua cpylua commented Dec 27, 2022

// 输入 1.289
function Demo1() {
  const [value, setValue] = React.useState("1.00");

  return <NumberInput value={value} onChange={setValue} decimal={2} />;
}

function Demo2() {
  const [value, setValue] = React.useState(0);
  const [datasets, setDatasets] = React.useState([
    {
      id: 1,
      name: "test",
      value: 129,
    },
  ]);

  return (
    <>
      <NumberInput
        placeholder=""
        width={120}
        value={Number(value) / 100}
        max={100}
        min={0}
        addonAfter="%"
        decimal={2}
        onChange={(val) => {
          setValue(val);
        }}
      />
      <NumberInput
        placeholder=""
        width={120}
        value={Number(datasets[0].value) / 100}
        max={100}
        min={0}
        addonAfter="%"
        decimal={2}
        onChange={(val) => {
          console.log("onChange");
          const newData = [...datasets];
          newData[0].value = Number(val) * 100;
          setDatasets(newData);
        }}
      />
    </>
  );
}

@cpylua cpylua merged commit 2df3c2c into v9 Dec 27, 2022
@cpylua cpylua deleted the fix-numberinput-infinite-loop-v9-20221227 branch December 27, 2022 10:35
cpylua added a commit that referenced this pull request Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant