Can't seem to use null as a default value?
See original GitHub issueI have a custom input component that declares:
Component.propTypes = {
value: PropTypes.number
};
Because mobx-react-form defaults the value to an empty string, I’m getting proptype errors in the console. So, I figured I could override the default value and set it to null, but an empty string still seems to be getting passed in. I tried default: null
, initial: null
, and value: null
, but nothing worked.
I’ve tried looking for documentation about default values, but I couldn’t seem to find much of anything. Sorry for asking questions in the issue tracker 😄 .
At the risk of more configuration boilerplate, do you think it would it be best for users to provide their own default values instead of assuming an empty string?
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
NULL and DEFAULT value: MySql behavior does not seem ...
1 Answer 1 ... You are "forcing" to insert null value in a field that can't be null, it has default value, ok,...
Read more >BIRT » Why can't parameter default values be NULL?
However, I can't seem to pass in null values no matter what. First, I can't set a dataset param default value to null...
Read more >11.6 Data Type Default Values
If the column cannot take NULL as a value, MySQL defines the column with no explicit DEFAULT clause.
Read more >Setting default value to NULL values when using Get-ADUser
I have tried a ForEach loop statement but I can't seem to figure this one out. What is not explicitly allowed should be...
Read more >Dart Null Safety: The Ultimate Guide to Non-Nullable Types
Non-nullable variables must always be initialized with non-null values. To fully understand all the Null Safety features, practice using them with Dartpad. Dart ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For the record, I make it work with this :
So in the case of
<input />
, it can’t be null. But, in the case of a custom input component,null
is actually very common I think.<ReactSelect />
, for example, can be null.Input components really just need to follow the contract of
value/onChange
. They might invokeonChange
with an array or an object. You wouldn’t want the initial value of an input that callsonChange
with an object to take an empty string as an initial value. Therefore,null
makes the most sense.This is a contrived example, but imagine you have a custom input component that knows how to manage objects with a certain structure.
Create the form:
This will trigger a propType error, because the distance input expects
null
or anobject
.