Comments (1)
I've also run into this and narrowed it down to the fact that NaN !== NaN
. If you use the lodash function isEqual
for the equality comparison then it should work a lot more reliably.
e.g.
if (!isEqual(value, previous)) {
this.setState({ previous: value })
children(value, previous)
}
Below is a failing test that confirms the issue (it fails due to "Maximum update depth exceeded.").
it('should only invoke the listener once when a number field is cleared', async () => {
const spy = jest.fn();
render(
<Form onSubmit={() => {}} initialValues={{ value: 1 }}>
{() => (
<form>
<Field<number> name="value">
{({ input: { onChange, value, ...inputRest } }) => (
<input
{...inputRest}
value={value}
type="number"
onChange={e => onChange(e.target.valueAsNumber)}
/>
)}
</Field>
<OnChange name="value">{spy}</OnChange>
</form>
)}
</Form>
);
expect(spy).not.toHaveBeenCalled();
await userEvent.clear(getByRole('spinbutton'));
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(NaN, 1);
});
from react-final-form-listeners.
Related Issues (13)
- Hooks feature
- OnFocus only fires once HOT 2
- Why are these implemented as external listeners rather than in RFF? HOT 2
- <OnChange> without name attribute broken after react-final-form update HOT 1
- OnBlur doesn't work HOT 1
- OnChange leads to "ghost data" appearing in field
- React 18 support HOT 3
- Why onBlur did not pass value like onChange? HOT 1
- Extending support for react 18 HOT 1
- Successive clicks on label are throttling OnChange listener HOT 6
- OnChange function is called on every render instead of user interaction. HOT 4
- How to avoid looping if two fields change each other's values? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-final-form-listeners.