React-Modal “Cannot Read Property of State of Null” Error












0















I am building a react-redux app where after a citation is generated the user has the option to save the citation to a separate list. I import Modal from 'react-modal' and then dispatch to the store information about the citation. It then redirects me to the citation list successfully. However, if I go to add another citation and click one of the header buttons (one going home or the other going to the citation list) before triggering the Modal, then I get the error "Cannot read property of state of null." If I remove the modal, then I do not get the error so I know it is related to the modal. Any help would be greatly appreciated. Here is the relevant code:



<SaveModal
fullCitation={this.state.fullCitation}
saveCitation={this.state.saveCitation}
handleClearSaveCitation={this.handleClearSaveCitation}
history={this.props.history}
createdAt={this.state.createdAt}
type={this.state.type}
note={this.state.note}
dispatch={this.props.dispatch}
handleAddType={this.handleAddType}
handleAddNote={this.handleAddNote}
/>

import React from 'react';
import Modal from 'react-modal';
import { connect } from 'react-redux';
import { addCitation } from '../actions/citations';

const SaveModal = (props) => (
<Modal
isOpen={props.saveCitation}
onRequestClose={props.handleClearSaveCitation}
contentLabel="SaveModal"
closeTimeoutMS={200}
className="modal"
>
<h3>{props.fullCitation}</h3>
<h3>{props.createdAt}</h3>
<input
autoFocus
className="text-input"
type="text"
id="type"
placeholder="Add Type (Optional)"
onChange={props.handleAddType}
/>
<textarea
id="textarea"
className="text-input"
placeholder="Add Note (Optional)"
onChange={props.handleAddNote}
>
</textarea>
<button
className="button"
onClick={() => {
props.dispatch(addCitation({
fullCitation: props.fullCitation,
createdAt: props.createdAt,
type: props.type,
note: props.note
}));
props.history.push('/CitationList');
}}
>Save</button>
</Modal>
);

export default connect()(SaveModal);


UPDATE:



The state is defined in the parent component and then passed down to Modal. A bunch of methods follow that manipulate the state before it is passed down to child components such as AddParties.



import React from 'react';
import term from '../term';
import AddParties from '../components/AddParties';
import AddOhioVolume from '../components/AddOhioVolume';
import AddRegionalVolume from '../components/AddRegionalVolume';
import AddYear from '../components/AddYear';
import AddPinpoint from '../components/AddPinpoint';
import AddWebcite from '../components/AddWebcite';
import CiteCase from '../components/CiteCase';
import Citation from '../components/Citation';
import RemoveCitation from '../components/RemoveCitation';
import CopyCitation from '../components/CopyCitation';
import SaveCitation from '../components/SaveCitation';
import moment from 'moment';
import SaveModal from '../components/SaveModal';


export default class SupremePost extends React.Component {
state = {
partyOne: "",
partyTwo: "",
ohioVolume: "",
ohioReporter: "",
ohioFirstPage: "",
regionalVolume: "",
regionalReporter: "",
regionalFirstPage: "",
year: "",
pinpointNumber: "",
pinpointDisplay: "",
webcite: "",
parties: "",
citation: "",
fullCitation: "",
createdAt: "",
saveCitation: false,
type: "None",
note: "None"
};









share|improve this question

























  • I guess Redux out of the box only works with Stateful component and you are using a stateless component here. Try making it stateful (extends component) and see if it works?

    – NoobieSatan
    Nov 23 '18 at 14:00











  • The first message below the "property state of null" is Modal.componentWillUnmount (Modal.js:119) I think that may have something to do with it. It does not make sense that I cannot route to other pages while I am on a page with Modal. Everything else works in terms of viewing the state and seeing the proper dispatch to the store when I am actually using the modal.

    – Nick Buzzy
    Nov 23 '18 at 14:05













  • BUT WHERE is your state defined? Where is eg. this.state.note. Redux are props shared globally, and state is local. In provided code state is null.

    – Zydnar
    Nov 23 '18 at 14:10













  • This is state in SupremePost but SaveModal compoment is type of Modal. How do you inherit this state form SupremePost?

    – Zydnar
    Nov 23 '18 at 14:20











  • I don’t understand what you mean, the code above shows how the state is passed in as props to the Modal

    – Nick Buzzy
    Nov 23 '18 at 14:24
















0















I am building a react-redux app where after a citation is generated the user has the option to save the citation to a separate list. I import Modal from 'react-modal' and then dispatch to the store information about the citation. It then redirects me to the citation list successfully. However, if I go to add another citation and click one of the header buttons (one going home or the other going to the citation list) before triggering the Modal, then I get the error "Cannot read property of state of null." If I remove the modal, then I do not get the error so I know it is related to the modal. Any help would be greatly appreciated. Here is the relevant code:



<SaveModal
fullCitation={this.state.fullCitation}
saveCitation={this.state.saveCitation}
handleClearSaveCitation={this.handleClearSaveCitation}
history={this.props.history}
createdAt={this.state.createdAt}
type={this.state.type}
note={this.state.note}
dispatch={this.props.dispatch}
handleAddType={this.handleAddType}
handleAddNote={this.handleAddNote}
/>

import React from 'react';
import Modal from 'react-modal';
import { connect } from 'react-redux';
import { addCitation } from '../actions/citations';

const SaveModal = (props) => (
<Modal
isOpen={props.saveCitation}
onRequestClose={props.handleClearSaveCitation}
contentLabel="SaveModal"
closeTimeoutMS={200}
className="modal"
>
<h3>{props.fullCitation}</h3>
<h3>{props.createdAt}</h3>
<input
autoFocus
className="text-input"
type="text"
id="type"
placeholder="Add Type (Optional)"
onChange={props.handleAddType}
/>
<textarea
id="textarea"
className="text-input"
placeholder="Add Note (Optional)"
onChange={props.handleAddNote}
>
</textarea>
<button
className="button"
onClick={() => {
props.dispatch(addCitation({
fullCitation: props.fullCitation,
createdAt: props.createdAt,
type: props.type,
note: props.note
}));
props.history.push('/CitationList');
}}
>Save</button>
</Modal>
);

export default connect()(SaveModal);


UPDATE:



The state is defined in the parent component and then passed down to Modal. A bunch of methods follow that manipulate the state before it is passed down to child components such as AddParties.



import React from 'react';
import term from '../term';
import AddParties from '../components/AddParties';
import AddOhioVolume from '../components/AddOhioVolume';
import AddRegionalVolume from '../components/AddRegionalVolume';
import AddYear from '../components/AddYear';
import AddPinpoint from '../components/AddPinpoint';
import AddWebcite from '../components/AddWebcite';
import CiteCase from '../components/CiteCase';
import Citation from '../components/Citation';
import RemoveCitation from '../components/RemoveCitation';
import CopyCitation from '../components/CopyCitation';
import SaveCitation from '../components/SaveCitation';
import moment from 'moment';
import SaveModal from '../components/SaveModal';


export default class SupremePost extends React.Component {
state = {
partyOne: "",
partyTwo: "",
ohioVolume: "",
ohioReporter: "",
ohioFirstPage: "",
regionalVolume: "",
regionalReporter: "",
regionalFirstPage: "",
year: "",
pinpointNumber: "",
pinpointDisplay: "",
webcite: "",
parties: "",
citation: "",
fullCitation: "",
createdAt: "",
saveCitation: false,
type: "None",
note: "None"
};









share|improve this question

























  • I guess Redux out of the box only works with Stateful component and you are using a stateless component here. Try making it stateful (extends component) and see if it works?

    – NoobieSatan
    Nov 23 '18 at 14:00











  • The first message below the "property state of null" is Modal.componentWillUnmount (Modal.js:119) I think that may have something to do with it. It does not make sense that I cannot route to other pages while I am on a page with Modal. Everything else works in terms of viewing the state and seeing the proper dispatch to the store when I am actually using the modal.

    – Nick Buzzy
    Nov 23 '18 at 14:05













  • BUT WHERE is your state defined? Where is eg. this.state.note. Redux are props shared globally, and state is local. In provided code state is null.

    – Zydnar
    Nov 23 '18 at 14:10













  • This is state in SupremePost but SaveModal compoment is type of Modal. How do you inherit this state form SupremePost?

    – Zydnar
    Nov 23 '18 at 14:20











  • I don’t understand what you mean, the code above shows how the state is passed in as props to the Modal

    – Nick Buzzy
    Nov 23 '18 at 14:24














0












0








0








I am building a react-redux app where after a citation is generated the user has the option to save the citation to a separate list. I import Modal from 'react-modal' and then dispatch to the store information about the citation. It then redirects me to the citation list successfully. However, if I go to add another citation and click one of the header buttons (one going home or the other going to the citation list) before triggering the Modal, then I get the error "Cannot read property of state of null." If I remove the modal, then I do not get the error so I know it is related to the modal. Any help would be greatly appreciated. Here is the relevant code:



<SaveModal
fullCitation={this.state.fullCitation}
saveCitation={this.state.saveCitation}
handleClearSaveCitation={this.handleClearSaveCitation}
history={this.props.history}
createdAt={this.state.createdAt}
type={this.state.type}
note={this.state.note}
dispatch={this.props.dispatch}
handleAddType={this.handleAddType}
handleAddNote={this.handleAddNote}
/>

import React from 'react';
import Modal from 'react-modal';
import { connect } from 'react-redux';
import { addCitation } from '../actions/citations';

const SaveModal = (props) => (
<Modal
isOpen={props.saveCitation}
onRequestClose={props.handleClearSaveCitation}
contentLabel="SaveModal"
closeTimeoutMS={200}
className="modal"
>
<h3>{props.fullCitation}</h3>
<h3>{props.createdAt}</h3>
<input
autoFocus
className="text-input"
type="text"
id="type"
placeholder="Add Type (Optional)"
onChange={props.handleAddType}
/>
<textarea
id="textarea"
className="text-input"
placeholder="Add Note (Optional)"
onChange={props.handleAddNote}
>
</textarea>
<button
className="button"
onClick={() => {
props.dispatch(addCitation({
fullCitation: props.fullCitation,
createdAt: props.createdAt,
type: props.type,
note: props.note
}));
props.history.push('/CitationList');
}}
>Save</button>
</Modal>
);

export default connect()(SaveModal);


UPDATE:



The state is defined in the parent component and then passed down to Modal. A bunch of methods follow that manipulate the state before it is passed down to child components such as AddParties.



import React from 'react';
import term from '../term';
import AddParties from '../components/AddParties';
import AddOhioVolume from '../components/AddOhioVolume';
import AddRegionalVolume from '../components/AddRegionalVolume';
import AddYear from '../components/AddYear';
import AddPinpoint from '../components/AddPinpoint';
import AddWebcite from '../components/AddWebcite';
import CiteCase from '../components/CiteCase';
import Citation from '../components/Citation';
import RemoveCitation from '../components/RemoveCitation';
import CopyCitation from '../components/CopyCitation';
import SaveCitation from '../components/SaveCitation';
import moment from 'moment';
import SaveModal from '../components/SaveModal';


export default class SupremePost extends React.Component {
state = {
partyOne: "",
partyTwo: "",
ohioVolume: "",
ohioReporter: "",
ohioFirstPage: "",
regionalVolume: "",
regionalReporter: "",
regionalFirstPage: "",
year: "",
pinpointNumber: "",
pinpointDisplay: "",
webcite: "",
parties: "",
citation: "",
fullCitation: "",
createdAt: "",
saveCitation: false,
type: "None",
note: "None"
};









share|improve this question
















I am building a react-redux app where after a citation is generated the user has the option to save the citation to a separate list. I import Modal from 'react-modal' and then dispatch to the store information about the citation. It then redirects me to the citation list successfully. However, if I go to add another citation and click one of the header buttons (one going home or the other going to the citation list) before triggering the Modal, then I get the error "Cannot read property of state of null." If I remove the modal, then I do not get the error so I know it is related to the modal. Any help would be greatly appreciated. Here is the relevant code:



<SaveModal
fullCitation={this.state.fullCitation}
saveCitation={this.state.saveCitation}
handleClearSaveCitation={this.handleClearSaveCitation}
history={this.props.history}
createdAt={this.state.createdAt}
type={this.state.type}
note={this.state.note}
dispatch={this.props.dispatch}
handleAddType={this.handleAddType}
handleAddNote={this.handleAddNote}
/>

import React from 'react';
import Modal from 'react-modal';
import { connect } from 'react-redux';
import { addCitation } from '../actions/citations';

const SaveModal = (props) => (
<Modal
isOpen={props.saveCitation}
onRequestClose={props.handleClearSaveCitation}
contentLabel="SaveModal"
closeTimeoutMS={200}
className="modal"
>
<h3>{props.fullCitation}</h3>
<h3>{props.createdAt}</h3>
<input
autoFocus
className="text-input"
type="text"
id="type"
placeholder="Add Type (Optional)"
onChange={props.handleAddType}
/>
<textarea
id="textarea"
className="text-input"
placeholder="Add Note (Optional)"
onChange={props.handleAddNote}
>
</textarea>
<button
className="button"
onClick={() => {
props.dispatch(addCitation({
fullCitation: props.fullCitation,
createdAt: props.createdAt,
type: props.type,
note: props.note
}));
props.history.push('/CitationList');
}}
>Save</button>
</Modal>
);

export default connect()(SaveModal);


UPDATE:



The state is defined in the parent component and then passed down to Modal. A bunch of methods follow that manipulate the state before it is passed down to child components such as AddParties.



import React from 'react';
import term from '../term';
import AddParties from '../components/AddParties';
import AddOhioVolume from '../components/AddOhioVolume';
import AddRegionalVolume from '../components/AddRegionalVolume';
import AddYear from '../components/AddYear';
import AddPinpoint from '../components/AddPinpoint';
import AddWebcite from '../components/AddWebcite';
import CiteCase from '../components/CiteCase';
import Citation from '../components/Citation';
import RemoveCitation from '../components/RemoveCitation';
import CopyCitation from '../components/CopyCitation';
import SaveCitation from '../components/SaveCitation';
import moment from 'moment';
import SaveModal from '../components/SaveModal';


export default class SupremePost extends React.Component {
state = {
partyOne: "",
partyTwo: "",
ohioVolume: "",
ohioReporter: "",
ohioFirstPage: "",
regionalVolume: "",
regionalReporter: "",
regionalFirstPage: "",
year: "",
pinpointNumber: "",
pinpointDisplay: "",
webcite: "",
parties: "",
citation: "",
fullCitation: "",
createdAt: "",
saveCitation: false,
type: "None",
note: "None"
};






javascript reactjs redux






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 14:16







Nick Buzzy

















asked Nov 23 '18 at 13:50









Nick BuzzyNick Buzzy

325




325













  • I guess Redux out of the box only works with Stateful component and you are using a stateless component here. Try making it stateful (extends component) and see if it works?

    – NoobieSatan
    Nov 23 '18 at 14:00











  • The first message below the "property state of null" is Modal.componentWillUnmount (Modal.js:119) I think that may have something to do with it. It does not make sense that I cannot route to other pages while I am on a page with Modal. Everything else works in terms of viewing the state and seeing the proper dispatch to the store when I am actually using the modal.

    – Nick Buzzy
    Nov 23 '18 at 14:05













  • BUT WHERE is your state defined? Where is eg. this.state.note. Redux are props shared globally, and state is local. In provided code state is null.

    – Zydnar
    Nov 23 '18 at 14:10













  • This is state in SupremePost but SaveModal compoment is type of Modal. How do you inherit this state form SupremePost?

    – Zydnar
    Nov 23 '18 at 14:20











  • I don’t understand what you mean, the code above shows how the state is passed in as props to the Modal

    – Nick Buzzy
    Nov 23 '18 at 14:24



















  • I guess Redux out of the box only works with Stateful component and you are using a stateless component here. Try making it stateful (extends component) and see if it works?

    – NoobieSatan
    Nov 23 '18 at 14:00











  • The first message below the "property state of null" is Modal.componentWillUnmount (Modal.js:119) I think that may have something to do with it. It does not make sense that I cannot route to other pages while I am on a page with Modal. Everything else works in terms of viewing the state and seeing the proper dispatch to the store when I am actually using the modal.

    – Nick Buzzy
    Nov 23 '18 at 14:05













  • BUT WHERE is your state defined? Where is eg. this.state.note. Redux are props shared globally, and state is local. In provided code state is null.

    – Zydnar
    Nov 23 '18 at 14:10













  • This is state in SupremePost but SaveModal compoment is type of Modal. How do you inherit this state form SupremePost?

    – Zydnar
    Nov 23 '18 at 14:20











  • I don’t understand what you mean, the code above shows how the state is passed in as props to the Modal

    – Nick Buzzy
    Nov 23 '18 at 14:24

















I guess Redux out of the box only works with Stateful component and you are using a stateless component here. Try making it stateful (extends component) and see if it works?

– NoobieSatan
Nov 23 '18 at 14:00





I guess Redux out of the box only works with Stateful component and you are using a stateless component here. Try making it stateful (extends component) and see if it works?

– NoobieSatan
Nov 23 '18 at 14:00













The first message below the "property state of null" is Modal.componentWillUnmount (Modal.js:119) I think that may have something to do with it. It does not make sense that I cannot route to other pages while I am on a page with Modal. Everything else works in terms of viewing the state and seeing the proper dispatch to the store when I am actually using the modal.

– Nick Buzzy
Nov 23 '18 at 14:05







The first message below the "property state of null" is Modal.componentWillUnmount (Modal.js:119) I think that may have something to do with it. It does not make sense that I cannot route to other pages while I am on a page with Modal. Everything else works in terms of viewing the state and seeing the proper dispatch to the store when I am actually using the modal.

– Nick Buzzy
Nov 23 '18 at 14:05















BUT WHERE is your state defined? Where is eg. this.state.note. Redux are props shared globally, and state is local. In provided code state is null.

– Zydnar
Nov 23 '18 at 14:10







BUT WHERE is your state defined? Where is eg. this.state.note. Redux are props shared globally, and state is local. In provided code state is null.

– Zydnar
Nov 23 '18 at 14:10















This is state in SupremePost but SaveModal compoment is type of Modal. How do you inherit this state form SupremePost?

– Zydnar
Nov 23 '18 at 14:20





This is state in SupremePost but SaveModal compoment is type of Modal. How do you inherit this state form SupremePost?

– Zydnar
Nov 23 '18 at 14:20













I don’t understand what you mean, the code above shows how the state is passed in as props to the Modal

– Nick Buzzy
Nov 23 '18 at 14:24





I don’t understand what you mean, the code above shows how the state is passed in as props to the Modal

– Nick Buzzy
Nov 23 '18 at 14:24












1 Answer
1






active

oldest

votes


















1














Apparently, I was using an outdated version of react-modal. I updated it, and now I have no further issues.






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%2f53447949%2freact-modal-cannot-read-property-of-state-of-null-error%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Apparently, I was using an outdated version of react-modal. I updated it, and now I have no further issues.






    share|improve this answer




























      1














      Apparently, I was using an outdated version of react-modal. I updated it, and now I have no further issues.






      share|improve this answer


























        1












        1








        1







        Apparently, I was using an outdated version of react-modal. I updated it, and now I have no further issues.






        share|improve this answer













        Apparently, I was using an outdated version of react-modal. I updated it, and now I have no further issues.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 15:14









        Nick BuzzyNick Buzzy

        325




        325






























            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%2f53447949%2freact-modal-cannot-read-property-of-state-of-null-error%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

            Sphinx de Gizeh

            Dijon

            Langue