Comments (6)
Reward for tracing it to the source was at least finding a work-around, which is to pass in a constant.
const defaultValue = []
const form = () => (
<SimpleForm>
<SelectArrayInput defaultValue={defaultValue} />
</SimpleForm>
)
from admin-on-rest.
That's a common React gotcha: you're passing a new empty array object each time the form rerenders, and specifying a default value rerenders the form. You have to define the default value as a constant (as we've explained for the validators, too).
from admin-on-rest.
I'm aware the code is creating a new Array
instance on each render. The fact that it creates infinite update loop is clearly not a "React gotcha", but a bug in how defaultValue
is being handled - re-rendering the whole form on defaultValue
change has nothing to do with React, it's your choice and it's not obvious in the least. (And if I needed the defaultValue
to actually change, I'd have to do some shenanigans like keeping it in an instance property to work around this behaviour.)
I'd say this warrants a clear warning in the docs at the very least. Additionally, the setup seemed to work not too far back, so maybe this changed with some dependency update.
Even more interesting (but unrelated) is how a function in defaultValue
is handled. Accepting a function without arguments only makes sense if it's not expected to be pure. Then resolving it only when the function changes doesn't seem to make much sense.
from admin-on-rest.
Btw. the docs actually contain code samples with the same issue (see defaultValue={new Date()}
and defaultValue={() => uuid()}
), which illustrates my point pretty well.
from admin-on-rest.
We're relying on redux-form for handling default values. I believe the problem lies there.
from admin-on-rest.
Nope, you're in control of dispatching its INITIALIZE
action. redux-form
only reacts by updating the form but doesn't control how this affects the place where you dispatch the action from. (It has no insight into the structure of the app using it.)
from admin-on-rest.
Related Issues (20)
- ReferenceArrayField not setting setSort
- Disable translate
- Upgrade to Angular 6 HOT 1
- different api call HOT 2
- Infinite Loading
- BooleanInput's defaultValue of false does not persist on initial load for validate function
- Too many columns can not view all columns
- ImageField show warnings HOT 1
- How to provide a custom redirect to a SimpleForm inside Edit ? HOT 2
- ReferenceInput not triggering "waiting" state after first load even when matchingReferences not yet loaded
- Handling server errors with SimpleForm HOT 2
- Headers should be lowercase HOT 1
- The tabs do not rerender on state change HOT 2
- Yarn check warning: error admin-on-rest > react-router-dom > react@^15" doesn't satisfy found match of "[email protected]"
- AutocompleteInput text not shown on edit
- ReferenceManyField not rendering data after first load (cache issue?) HOT 2
- SelectArrayInput component required validation not working
- Can't create a production build HOT 1
- When will Material UI be updated to version 1? HOT 2
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 admin-on-rest.