React PropType is not giving error when isRequired is used
I am trying to learn React but the PropTypes
even when used with isRequired
is not throwing any error. Am i doing something wrong.
The code is like this
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/prop-types@15.6.2/prop-types.min.js"></script>
<script crossorigin src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<script type="text/babel">
function SayHello(props) {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
)
}
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired,
}
ReactDOM.render(<SayHello />, document.getElementById('root'))
</script>
Shouldn't this throw an error
or a warning
when firstName
and lastName
isn't sent.
Thus making those two props mandatory similar to this.
<SayHello firstName="John" lastName="Doe" />
I am getting no error or warning on my browser.
reactjs react-proptypes
add a comment |
I am trying to learn React but the PropTypes
even when used with isRequired
is not throwing any error. Am i doing something wrong.
The code is like this
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/prop-types@15.6.2/prop-types.min.js"></script>
<script crossorigin src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<script type="text/babel">
function SayHello(props) {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
)
}
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired,
}
ReactDOM.render(<SayHello />, document.getElementById('root'))
</script>
Shouldn't this throw an error
or a warning
when firstName
and lastName
isn't sent.
Thus making those two props mandatory similar to this.
<SayHello firstName="John" lastName="Doe" />
I am getting no error or warning on my browser.
reactjs react-proptypes
Hi, have you checked the browser console? proptypes throws errors there, it doesn't show anything on the actual browser view port..
– bullettrain
yesterday
@bullettrain, I am checking the browser console only. Even a babel warning aboutin-browser Babel transformer
pops up but nothing else.
– Nithin
yesterday
add a comment |
I am trying to learn React but the PropTypes
even when used with isRequired
is not throwing any error. Am i doing something wrong.
The code is like this
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/prop-types@15.6.2/prop-types.min.js"></script>
<script crossorigin src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<script type="text/babel">
function SayHello(props) {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
)
}
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired,
}
ReactDOM.render(<SayHello />, document.getElementById('root'))
</script>
Shouldn't this throw an error
or a warning
when firstName
and lastName
isn't sent.
Thus making those two props mandatory similar to this.
<SayHello firstName="John" lastName="Doe" />
I am getting no error or warning on my browser.
reactjs react-proptypes
I am trying to learn React but the PropTypes
even when used with isRequired
is not throwing any error. Am i doing something wrong.
The code is like this
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/prop-types@15.6.2/prop-types.min.js"></script>
<script crossorigin src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<script type="text/babel">
function SayHello(props) {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
)
}
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired,
}
ReactDOM.render(<SayHello />, document.getElementById('root'))
</script>
Shouldn't this throw an error
or a warning
when firstName
and lastName
isn't sent.
Thus making those two props mandatory similar to this.
<SayHello firstName="John" lastName="Doe" />
I am getting no error or warning on my browser.
reactjs react-proptypes
reactjs react-proptypes
edited yesterday
Praveen Rao Chavan.G
1,044616
1,044616
asked yesterday
NithinNithin
318112
318112
Hi, have you checked the browser console? proptypes throws errors there, it doesn't show anything on the actual browser view port..
– bullettrain
yesterday
@bullettrain, I am checking the browser console only. Even a babel warning aboutin-browser Babel transformer
pops up but nothing else.
– Nithin
yesterday
add a comment |
Hi, have you checked the browser console? proptypes throws errors there, it doesn't show anything on the actual browser view port..
– bullettrain
yesterday
@bullettrain, I am checking the browser console only. Even a babel warning aboutin-browser Babel transformer
pops up but nothing else.
– Nithin
yesterday
Hi, have you checked the browser console? proptypes throws errors there, it doesn't show anything on the actual browser view port..
– bullettrain
yesterday
Hi, have you checked the browser console? proptypes throws errors there, it doesn't show anything on the actual browser view port..
– bullettrain
yesterday
@bullettrain, I am checking the browser console only. Even a babel warning about
in-browser Babel transformer
pops up but nothing else.– Nithin
yesterday
@bullettrain, I am checking the browser console only. Even a babel warning about
in-browser Babel transformer
pops up but nothing else.– Nithin
yesterday
add a comment |
3 Answers
3
active
oldest
votes
It might be some issue with minified version of proptypes.
Change your
https://unpkg.com/prop-types@15.6.2/prop-types.min.js
to
https://unpkg.com/prop-types@15.6.2/prop-types.js
You will get warning Failed proptype.
Thank you. But shouldn't the minified versions have the same code but with no comments and line breaks? I know aboutjQuery
and their versions but here?
– Nithin
yesterday
1
It's my pleasure. Yes, minified version must provide same functionality by removing unnecessary code. In this case there might be some different issue.
– JS Engine
yesterday
add a comment |
here is the working solution https://codesandbox.io/s/ymorp9y17v
import * as PropTypes from "prop-types";
const SayHello = props => {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
);
};
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired
};
export default SayHello;
import PropTypes from 'prop-types';
is fine. There's no need for the*
– Josh Kelly
yesterday
Yep, It throws an error. But, What was wrong with my code in the first place? Also my code still does not throw an error.
– Nithin
yesterday
I updated the snippet: codesandbox.io/s/ymorp9y17v. I don't exactly know why force*
import, but my IDE says: Default export is not declared in imported module
– landorid
yesterday
It still didn't throw an error. I changed theunpkg
versions and it works.
– Nithin
yesterday
add a comment |
EDIT
@JS Engine correct, change PropTypes from production version to development version.
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/prop-types@15.6.2/prop-types.js"></script>
<script crossorigin src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<script type="text/babel">
function SayHello(props) {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
)
}
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired,
}
ReactDOM.render(<SayHello />, document.getElementById('root'))
</script>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54251815%2freact-proptype-is-not-giving-error-when-isrequired-is-used%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
It might be some issue with minified version of proptypes.
Change your
https://unpkg.com/prop-types@15.6.2/prop-types.min.js
to
https://unpkg.com/prop-types@15.6.2/prop-types.js
You will get warning Failed proptype.
Thank you. But shouldn't the minified versions have the same code but with no comments and line breaks? I know aboutjQuery
and their versions but here?
– Nithin
yesterday
1
It's my pleasure. Yes, minified version must provide same functionality by removing unnecessary code. In this case there might be some different issue.
– JS Engine
yesterday
add a comment |
It might be some issue with minified version of proptypes.
Change your
https://unpkg.com/prop-types@15.6.2/prop-types.min.js
to
https://unpkg.com/prop-types@15.6.2/prop-types.js
You will get warning Failed proptype.
Thank you. But shouldn't the minified versions have the same code but with no comments and line breaks? I know aboutjQuery
and their versions but here?
– Nithin
yesterday
1
It's my pleasure. Yes, minified version must provide same functionality by removing unnecessary code. In this case there might be some different issue.
– JS Engine
yesterday
add a comment |
It might be some issue with minified version of proptypes.
Change your
https://unpkg.com/prop-types@15.6.2/prop-types.min.js
to
https://unpkg.com/prop-types@15.6.2/prop-types.js
You will get warning Failed proptype.
It might be some issue with minified version of proptypes.
Change your
https://unpkg.com/prop-types@15.6.2/prop-types.min.js
to
https://unpkg.com/prop-types@15.6.2/prop-types.js
You will get warning Failed proptype.
answered yesterday
JS EngineJS Engine
33711
33711
Thank you. But shouldn't the minified versions have the same code but with no comments and line breaks? I know aboutjQuery
and their versions but here?
– Nithin
yesterday
1
It's my pleasure. Yes, minified version must provide same functionality by removing unnecessary code. In this case there might be some different issue.
– JS Engine
yesterday
add a comment |
Thank you. But shouldn't the minified versions have the same code but with no comments and line breaks? I know aboutjQuery
and their versions but here?
– Nithin
yesterday
1
It's my pleasure. Yes, minified version must provide same functionality by removing unnecessary code. In this case there might be some different issue.
– JS Engine
yesterday
Thank you. But shouldn't the minified versions have the same code but with no comments and line breaks? I know about
jQuery
and their versions but here?– Nithin
yesterday
Thank you. But shouldn't the minified versions have the same code but with no comments and line breaks? I know about
jQuery
and their versions but here?– Nithin
yesterday
1
1
It's my pleasure. Yes, minified version must provide same functionality by removing unnecessary code. In this case there might be some different issue.
– JS Engine
yesterday
It's my pleasure. Yes, minified version must provide same functionality by removing unnecessary code. In this case there might be some different issue.
– JS Engine
yesterday
add a comment |
here is the working solution https://codesandbox.io/s/ymorp9y17v
import * as PropTypes from "prop-types";
const SayHello = props => {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
);
};
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired
};
export default SayHello;
import PropTypes from 'prop-types';
is fine. There's no need for the*
– Josh Kelly
yesterday
Yep, It throws an error. But, What was wrong with my code in the first place? Also my code still does not throw an error.
– Nithin
yesterday
I updated the snippet: codesandbox.io/s/ymorp9y17v. I don't exactly know why force*
import, but my IDE says: Default export is not declared in imported module
– landorid
yesterday
It still didn't throw an error. I changed theunpkg
versions and it works.
– Nithin
yesterday
add a comment |
here is the working solution https://codesandbox.io/s/ymorp9y17v
import * as PropTypes from "prop-types";
const SayHello = props => {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
);
};
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired
};
export default SayHello;
import PropTypes from 'prop-types';
is fine. There's no need for the*
– Josh Kelly
yesterday
Yep, It throws an error. But, What was wrong with my code in the first place? Also my code still does not throw an error.
– Nithin
yesterday
I updated the snippet: codesandbox.io/s/ymorp9y17v. I don't exactly know why force*
import, but my IDE says: Default export is not declared in imported module
– landorid
yesterday
It still didn't throw an error. I changed theunpkg
versions and it works.
– Nithin
yesterday
add a comment |
here is the working solution https://codesandbox.io/s/ymorp9y17v
import * as PropTypes from "prop-types";
const SayHello = props => {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
);
};
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired
};
export default SayHello;
here is the working solution https://codesandbox.io/s/ymorp9y17v
import * as PropTypes from "prop-types";
const SayHello = props => {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
);
};
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired
};
export default SayHello;
answered yesterday
landoridlandorid
1013
1013
import PropTypes from 'prop-types';
is fine. There's no need for the*
– Josh Kelly
yesterday
Yep, It throws an error. But, What was wrong with my code in the first place? Also my code still does not throw an error.
– Nithin
yesterday
I updated the snippet: codesandbox.io/s/ymorp9y17v. I don't exactly know why force*
import, but my IDE says: Default export is not declared in imported module
– landorid
yesterday
It still didn't throw an error. I changed theunpkg
versions and it works.
– Nithin
yesterday
add a comment |
import PropTypes from 'prop-types';
is fine. There's no need for the*
– Josh Kelly
yesterday
Yep, It throws an error. But, What was wrong with my code in the first place? Also my code still does not throw an error.
– Nithin
yesterday
I updated the snippet: codesandbox.io/s/ymorp9y17v. I don't exactly know why force*
import, but my IDE says: Default export is not declared in imported module
– landorid
yesterday
It still didn't throw an error. I changed theunpkg
versions and it works.
– Nithin
yesterday
import PropTypes from 'prop-types';
is fine. There's no need for the *
– Josh Kelly
yesterday
import PropTypes from 'prop-types';
is fine. There's no need for the *
– Josh Kelly
yesterday
Yep, It throws an error. But, What was wrong with my code in the first place? Also my code still does not throw an error.
– Nithin
yesterday
Yep, It throws an error. But, What was wrong with my code in the first place? Also my code still does not throw an error.
– Nithin
yesterday
I updated the snippet: codesandbox.io/s/ymorp9y17v. I don't exactly know why force
*
import, but my IDE says: Default export is not declared in imported module– landorid
yesterday
I updated the snippet: codesandbox.io/s/ymorp9y17v. I don't exactly know why force
*
import, but my IDE says: Default export is not declared in imported module– landorid
yesterday
It still didn't throw an error. I changed the
unpkg
versions and it works.– Nithin
yesterday
It still didn't throw an error. I changed the
unpkg
versions and it works.– Nithin
yesterday
add a comment |
EDIT
@JS Engine correct, change PropTypes from production version to development version.
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/prop-types@15.6.2/prop-types.js"></script>
<script crossorigin src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<script type="text/babel">
function SayHello(props) {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
)
}
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired,
}
ReactDOM.render(<SayHello />, document.getElementById('root'))
</script>
add a comment |
EDIT
@JS Engine correct, change PropTypes from production version to development version.
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/prop-types@15.6.2/prop-types.js"></script>
<script crossorigin src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<script type="text/babel">
function SayHello(props) {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
)
}
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired,
}
ReactDOM.render(<SayHello />, document.getElementById('root'))
</script>
add a comment |
EDIT
@JS Engine correct, change PropTypes from production version to development version.
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/prop-types@15.6.2/prop-types.js"></script>
<script crossorigin src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<script type="text/babel">
function SayHello(props) {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
)
}
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired,
}
ReactDOM.render(<SayHello />, document.getElementById('root'))
</script>
EDIT
@JS Engine correct, change PropTypes from production version to development version.
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/prop-types@15.6.2/prop-types.js"></script>
<script crossorigin src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<script type="text/babel">
function SayHello(props) {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
)
}
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired,
}
ReactDOM.render(<SayHello />, document.getElementById('root'))
</script>
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/prop-types@15.6.2/prop-types.js"></script>
<script crossorigin src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<script type="text/babel">
function SayHello(props) {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
)
}
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired,
}
ReactDOM.render(<SayHello />, document.getElementById('root'))
</script>
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/prop-types@15.6.2/prop-types.js"></script>
<script crossorigin src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<script type="text/babel">
function SayHello(props) {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
)
}
SayHello.propTypes = {
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired,
}
ReactDOM.render(<SayHello />, document.getElementById('root'))
</script>
edited yesterday
answered yesterday
Kyaw Kyaw SoeKyaw Kyaw Soe
611211
611211
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54251815%2freact-proptype-is-not-giving-error-when-isrequired-is-used%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hi, have you checked the browser console? proptypes throws errors there, it doesn't show anything on the actual browser view port..
– bullettrain
yesterday
@bullettrain, I am checking the browser console only. Even a babel warning about
in-browser Babel transformer
pops up but nothing else.– Nithin
yesterday