beefancohen / react-proptype-conditional-require Goto Github PK
View Code? Open in Web Editor NEWConditionally require built-in or custom React proptypes based on other props.
License: MIT License
Conditionally require built-in or custom React proptypes based on other props.
License: MIT License
What if the conditional prop is a boolean value with a default value set to false
? Couldn't get this to work.
Examples form the README are incorrect. This line to be exact:
import isRequiredIf from 'react-proptype-conditional-require';
There's no index.js
file, so we can't import like this.
@evcohen You did a great job with this! It's too bad that prop-types
is in maintenance mode now and won't merge this in.
The company I work for went ahead and created a fork that adds isRequiredIf
functionality. It takes a function and gets passed the props, like:
id: PropTypes.number.isRequiredIf( props => !props.uid )
It doesn't take a boolean like yours does because we didn't require that.
Anyway, just wanted to say thanks for your efforts and if anybody is still stuck using prop-types
and wants to use a natural syntax for conditional requirements, feel free to use it. It can be found here:
https://github.com/cntral/prop-types/tree/isRequiredIf
And you can easily use it in your package.json
like so:
"prop-types": "github:cntral/prop-types#isRequiredIf"
๐ป
It would be awesome if this library was a no-op in production, similar to prop-types: https://github.com/facebook/prop-types/blob/11e45c433f439940a4a6fa280a4464ef449e8943/index.js#L8
The reasoning is two-fold: performance and small builds since webpack/uglify will remove dead-code if process.env.NODE_ENV
gets inlined.
Thank you very much for this extremely helpful library. I wanted to alert you to a non-critical issue that I noticed after installing the library in my React project (React version 16.0.0) -
In Chrome (version 63.0.3239.84), I'm getting the following warning:
DevTools failed to parse SourceMap: http://localhost:5000/js/isRequiredIf.js.map
and a slightly different variation in Firefox (version 57.0.3):
Source map error: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
Resource URL: http://localhost:5000/js/app.js
Source Map URL: isRequiredIf.js.map
No problems in Safari, though.
As far as I can tell, this is not affecting performance, but I thought you'd want to know.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.