react-component / react-component/pagination
Could props simple support controlled component
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 674
- Forks
- 333
- Avg merge
- 12m
- Merged PRs (30d)
- 1
Description
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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Pagination handleChange logic shown in the issue and trace how current, currentInputValue, and the simple-mode input are updated when current is controlled. Reproduce the example with a callback that sometimes does not update current, then verify that the input remains consistent with the controlled value and that input changes still trigger the expected callback behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100