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

Could props simple support controlled component #467

Open
zcma11 opened this issue Nov 25, 2022 · 0 comments
Open

Could props simple support controlled component #467

zcma11 opened this issue Nov 25, 2022 · 0 comments

Comments

@zcma11
Copy link

zcma11 commented Nov 25, 2022

when i use the pagination with props { simple: true, current: 1, onChange=() => {...}}

i met a bug, the current is be controlled by me, but the input is not.

the example is

const [current, setCurrent] = useState(1);
const onChange = (page) => {
  if (Math.random() > 0.5) {
    return
  } else {
    setCurrent(page)
  }
}

return (<Pagination
      simple
      current={current}
      onChange={onChange}
      total={50}
/>)

i expected when the current doesn't change, the input value should be 1.
i received "the input value is 2", currentInputValue becomes 2, but current is still 1

i guess the problem is caused by this part.

// handleChange
if (!('current' in this.props)) {
        this.setState({
          current: newPage,
        });
      }
      if (newPage !== currentInputValue) {
        this.setState({
          currentInputValue: newPage,
        });
      }

should the design can be "when found current in props, the currentInputValue can not be changed"?

the following problem is how to due with the change event of input

thank you

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

No branches or pull requests

1 participant