React PropType is not giving error when isRequired is used












0















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.










share|improve this question

























  • 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
















0















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.










share|improve this question

























  • 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














0












0








0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 about in-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











  • @bullettrain, I am checking the browser console only. Even a babel warning about in-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












3 Answers
3






active

oldest

votes


















2














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.






share|improve this answer
























  • 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





    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



















2














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;





share|improve this answer
























  • 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 the unpkg versions and it works.

    – Nithin
    yesterday



















1














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>








share|improve this answer

























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    2














    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.






    share|improve this answer
























    • 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





      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
















    2














    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.






    share|improve this answer
























    • 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





      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














    2












    2








    2







    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.






    share|improve this answer













    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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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 about jQuery 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






    • 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













    2














    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;





    share|improve this answer
























    • 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 the unpkg versions and it works.

      – Nithin
      yesterday
















    2














    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;





    share|improve this answer
























    • 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 the unpkg versions and it works.

      – Nithin
      yesterday














    2












    2








    2







    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;





    share|improve this answer













    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;






    share|improve this answer












    share|improve this answer



    share|improve this answer










    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 the unpkg versions and it works.

      – Nithin
      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











    • 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

















    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











    1














    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>








    share|improve this answer






























      1














      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>








      share|improve this answer




























        1












        1








        1







        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>








        share|improve this answer















        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>






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited yesterday

























        answered yesterday









        Kyaw Kyaw SoeKyaw Kyaw Soe

        611211




        611211






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Liquibase includeAll doesn't find base path

            How to use setInterval in EJS file?

            Petrus Granier-Deferre