React component doesn't connect to the store












0















I have been using this to create the following.



import React from 'react';
import ReactDOM from 'react-dom';
import {connect} from 'react-redux';
import PropTypes from 'prop-types';

import {Alert, No} from './pure/Icons/Icons';
import Button from './pure/Button/Button';
import Modal from './pure/Modal/Modal';

import {setWarning} from '../actions/app/appActions';

const WarningModal = ({withCleanup, message, isWarning}) => {
const [
title,
text,
leave,
cancel
] = message.split('|');

console.log(isWarning)

const handleOnClick = () => {
setWarning(false);
withCleanup(true);
}

return(
<Modal>
<header>{title}</header>
<p>{text}</p>
<Alert />
<div className="modal__buttons-wrapper modal__buttons-wrapper--center">
<button
onClick={() => withCleanup(false)}
className="button modal__close-button button--icon button--icon-only button--text-link"
>
<No />
</button>
<Button id="leave-warning-button" className="button--transparent-bg" onClick={() => handleOnClick()}>{leave}</Button>
<Button id="cancel-warning-button" onClick={() => withCleanup(false)}>{cancel}</Button>
</div>
</Modal>
);
}

WarningModal.propTypes = {
withCleanup: PropTypes.func.isRequired,
message: PropTypes.string.isRequired,
isWarning: PropTypes.bool.isRequired
};

const mapStateToProps = state => {
return {
isWarning: state.app.isWarning
}
};

connect(mapStateToProps, {
setWarning
})(WarningModal);

export default (message, callback) => {
const modal = document.createElement('div');
document.body.appendChild(modal);

const withCleanup = (answer) => {
ReactDOM.unmountComponentAtNode(modal);
document.body.removeChild(modal);
callback(answer);
};

ReactDOM.render(
<WarningModal
message={message}
withCleanup={withCleanup}
/>,
modal
);
};


I need to dispatch an action to update a state property ('isWarning') which controls the visibility of 'WarningModal', however this doesn't seem to connect my component to the store:



connect(mapStateToProps, {
setWarning
})(WarningModal);

ConfigureStore.js

...
return createStore(
combineReducers(reducers),
composeEnhancers(
applyMiddleware(...middlewares)
)
);
...









share|improve this question

























  • Are you using combineReducers? Can you share your reducer/rootReducer structure?

    – Alexander Staroselsky
    Nov 21 '18 at 17:03











  • please check this , stackoverflow.com/questions/50251827/…

    – DILEEP THOMAS
    Nov 21 '18 at 17:04











  • @AlexanderStaroselsky yes I am

    – Alex
    Nov 21 '18 at 17:08











  • I'm trying to understand if your mapStateToProps configured correctly. The question about the combineReducers was to get information regarding the keys/namespaces of your state/store. Can you console.log(state) inside mapStateToProps and share the output please?

    – Alexander Staroselsky
    Nov 21 '18 at 17:14











  • @AlexanderStaroselsky it's undefined, the relative action and reducers are called.

    – Alex
    Nov 21 '18 at 17:17
















0















I have been using this to create the following.



import React from 'react';
import ReactDOM from 'react-dom';
import {connect} from 'react-redux';
import PropTypes from 'prop-types';

import {Alert, No} from './pure/Icons/Icons';
import Button from './pure/Button/Button';
import Modal from './pure/Modal/Modal';

import {setWarning} from '../actions/app/appActions';

const WarningModal = ({withCleanup, message, isWarning}) => {
const [
title,
text,
leave,
cancel
] = message.split('|');

console.log(isWarning)

const handleOnClick = () => {
setWarning(false);
withCleanup(true);
}

return(
<Modal>
<header>{title}</header>
<p>{text}</p>
<Alert />
<div className="modal__buttons-wrapper modal__buttons-wrapper--center">
<button
onClick={() => withCleanup(false)}
className="button modal__close-button button--icon button--icon-only button--text-link"
>
<No />
</button>
<Button id="leave-warning-button" className="button--transparent-bg" onClick={() => handleOnClick()}>{leave}</Button>
<Button id="cancel-warning-button" onClick={() => withCleanup(false)}>{cancel}</Button>
</div>
</Modal>
);
}

WarningModal.propTypes = {
withCleanup: PropTypes.func.isRequired,
message: PropTypes.string.isRequired,
isWarning: PropTypes.bool.isRequired
};

const mapStateToProps = state => {
return {
isWarning: state.app.isWarning
}
};

connect(mapStateToProps, {
setWarning
})(WarningModal);

export default (message, callback) => {
const modal = document.createElement('div');
document.body.appendChild(modal);

const withCleanup = (answer) => {
ReactDOM.unmountComponentAtNode(modal);
document.body.removeChild(modal);
callback(answer);
};

ReactDOM.render(
<WarningModal
message={message}
withCleanup={withCleanup}
/>,
modal
);
};


I need to dispatch an action to update a state property ('isWarning') which controls the visibility of 'WarningModal', however this doesn't seem to connect my component to the store:



connect(mapStateToProps, {
setWarning
})(WarningModal);

ConfigureStore.js

...
return createStore(
combineReducers(reducers),
composeEnhancers(
applyMiddleware(...middlewares)
)
);
...









share|improve this question

























  • Are you using combineReducers? Can you share your reducer/rootReducer structure?

    – Alexander Staroselsky
    Nov 21 '18 at 17:03











  • please check this , stackoverflow.com/questions/50251827/…

    – DILEEP THOMAS
    Nov 21 '18 at 17:04











  • @AlexanderStaroselsky yes I am

    – Alex
    Nov 21 '18 at 17:08











  • I'm trying to understand if your mapStateToProps configured correctly. The question about the combineReducers was to get information regarding the keys/namespaces of your state/store. Can you console.log(state) inside mapStateToProps and share the output please?

    – Alexander Staroselsky
    Nov 21 '18 at 17:14











  • @AlexanderStaroselsky it's undefined, the relative action and reducers are called.

    – Alex
    Nov 21 '18 at 17:17














0












0








0








I have been using this to create the following.



import React from 'react';
import ReactDOM from 'react-dom';
import {connect} from 'react-redux';
import PropTypes from 'prop-types';

import {Alert, No} from './pure/Icons/Icons';
import Button from './pure/Button/Button';
import Modal from './pure/Modal/Modal';

import {setWarning} from '../actions/app/appActions';

const WarningModal = ({withCleanup, message, isWarning}) => {
const [
title,
text,
leave,
cancel
] = message.split('|');

console.log(isWarning)

const handleOnClick = () => {
setWarning(false);
withCleanup(true);
}

return(
<Modal>
<header>{title}</header>
<p>{text}</p>
<Alert />
<div className="modal__buttons-wrapper modal__buttons-wrapper--center">
<button
onClick={() => withCleanup(false)}
className="button modal__close-button button--icon button--icon-only button--text-link"
>
<No />
</button>
<Button id="leave-warning-button" className="button--transparent-bg" onClick={() => handleOnClick()}>{leave}</Button>
<Button id="cancel-warning-button" onClick={() => withCleanup(false)}>{cancel}</Button>
</div>
</Modal>
);
}

WarningModal.propTypes = {
withCleanup: PropTypes.func.isRequired,
message: PropTypes.string.isRequired,
isWarning: PropTypes.bool.isRequired
};

const mapStateToProps = state => {
return {
isWarning: state.app.isWarning
}
};

connect(mapStateToProps, {
setWarning
})(WarningModal);

export default (message, callback) => {
const modal = document.createElement('div');
document.body.appendChild(modal);

const withCleanup = (answer) => {
ReactDOM.unmountComponentAtNode(modal);
document.body.removeChild(modal);
callback(answer);
};

ReactDOM.render(
<WarningModal
message={message}
withCleanup={withCleanup}
/>,
modal
);
};


I need to dispatch an action to update a state property ('isWarning') which controls the visibility of 'WarningModal', however this doesn't seem to connect my component to the store:



connect(mapStateToProps, {
setWarning
})(WarningModal);

ConfigureStore.js

...
return createStore(
combineReducers(reducers),
composeEnhancers(
applyMiddleware(...middlewares)
)
);
...









share|improve this question
















I have been using this to create the following.



import React from 'react';
import ReactDOM from 'react-dom';
import {connect} from 'react-redux';
import PropTypes from 'prop-types';

import {Alert, No} from './pure/Icons/Icons';
import Button from './pure/Button/Button';
import Modal from './pure/Modal/Modal';

import {setWarning} from '../actions/app/appActions';

const WarningModal = ({withCleanup, message, isWarning}) => {
const [
title,
text,
leave,
cancel
] = message.split('|');

console.log(isWarning)

const handleOnClick = () => {
setWarning(false);
withCleanup(true);
}

return(
<Modal>
<header>{title}</header>
<p>{text}</p>
<Alert />
<div className="modal__buttons-wrapper modal__buttons-wrapper--center">
<button
onClick={() => withCleanup(false)}
className="button modal__close-button button--icon button--icon-only button--text-link"
>
<No />
</button>
<Button id="leave-warning-button" className="button--transparent-bg" onClick={() => handleOnClick()}>{leave}</Button>
<Button id="cancel-warning-button" onClick={() => withCleanup(false)}>{cancel}</Button>
</div>
</Modal>
);
}

WarningModal.propTypes = {
withCleanup: PropTypes.func.isRequired,
message: PropTypes.string.isRequired,
isWarning: PropTypes.bool.isRequired
};

const mapStateToProps = state => {
return {
isWarning: state.app.isWarning
}
};

connect(mapStateToProps, {
setWarning
})(WarningModal);

export default (message, callback) => {
const modal = document.createElement('div');
document.body.appendChild(modal);

const withCleanup = (answer) => {
ReactDOM.unmountComponentAtNode(modal);
document.body.removeChild(modal);
callback(answer);
};

ReactDOM.render(
<WarningModal
message={message}
withCleanup={withCleanup}
/>,
modal
);
};


I need to dispatch an action to update a state property ('isWarning') which controls the visibility of 'WarningModal', however this doesn't seem to connect my component to the store:



connect(mapStateToProps, {
setWarning
})(WarningModal);

ConfigureStore.js

...
return createStore(
combineReducers(reducers),
composeEnhancers(
applyMiddleware(...middlewares)
)
);
...






javascript reactjs redux react-redux






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 17:04







Alex

















asked Nov 21 '18 at 16:56









AlexAlex

1,78283980




1,78283980













  • Are you using combineReducers? Can you share your reducer/rootReducer structure?

    – Alexander Staroselsky
    Nov 21 '18 at 17:03











  • please check this , stackoverflow.com/questions/50251827/…

    – DILEEP THOMAS
    Nov 21 '18 at 17:04











  • @AlexanderStaroselsky yes I am

    – Alex
    Nov 21 '18 at 17:08











  • I'm trying to understand if your mapStateToProps configured correctly. The question about the combineReducers was to get information regarding the keys/namespaces of your state/store. Can you console.log(state) inside mapStateToProps and share the output please?

    – Alexander Staroselsky
    Nov 21 '18 at 17:14











  • @AlexanderStaroselsky it's undefined, the relative action and reducers are called.

    – Alex
    Nov 21 '18 at 17:17



















  • Are you using combineReducers? Can you share your reducer/rootReducer structure?

    – Alexander Staroselsky
    Nov 21 '18 at 17:03











  • please check this , stackoverflow.com/questions/50251827/…

    – DILEEP THOMAS
    Nov 21 '18 at 17:04











  • @AlexanderStaroselsky yes I am

    – Alex
    Nov 21 '18 at 17:08











  • I'm trying to understand if your mapStateToProps configured correctly. The question about the combineReducers was to get information regarding the keys/namespaces of your state/store. Can you console.log(state) inside mapStateToProps and share the output please?

    – Alexander Staroselsky
    Nov 21 '18 at 17:14











  • @AlexanderStaroselsky it's undefined, the relative action and reducers are called.

    – Alex
    Nov 21 '18 at 17:17

















Are you using combineReducers? Can you share your reducer/rootReducer structure?

– Alexander Staroselsky
Nov 21 '18 at 17:03





Are you using combineReducers? Can you share your reducer/rootReducer structure?

– Alexander Staroselsky
Nov 21 '18 at 17:03













please check this , stackoverflow.com/questions/50251827/…

– DILEEP THOMAS
Nov 21 '18 at 17:04





please check this , stackoverflow.com/questions/50251827/…

– DILEEP THOMAS
Nov 21 '18 at 17:04













@AlexanderStaroselsky yes I am

– Alex
Nov 21 '18 at 17:08





@AlexanderStaroselsky yes I am

– Alex
Nov 21 '18 at 17:08













I'm trying to understand if your mapStateToProps configured correctly. The question about the combineReducers was to get information regarding the keys/namespaces of your state/store. Can you console.log(state) inside mapStateToProps and share the output please?

– Alexander Staroselsky
Nov 21 '18 at 17:14





I'm trying to understand if your mapStateToProps configured correctly. The question about the combineReducers was to get information regarding the keys/namespaces of your state/store. Can you console.log(state) inside mapStateToProps and share the output please?

– Alexander Staroselsky
Nov 21 '18 at 17:14













@AlexanderStaroselsky it's undefined, the relative action and reducers are called.

– Alex
Nov 21 '18 at 17:17





@AlexanderStaroselsky it's undefined, the relative action and reducers are called.

– Alex
Nov 21 '18 at 17:17












2 Answers
2






active

oldest

votes


















0














The call to connect() returns a wrapped React component constructor. This code is not using the return value of connect at all, so it's thrown away.



The smallest change that should fix this would be to save the return value from connect in a new variable, and use that in place of WarningModal in the exported component constructor's render function:



const WarningModalContainer = connect(mapStateToProps, {
setWarning
})(WarningModal);


...



ReactDOM.render(
<WarningModalContainer
message={message}
withCleanup={withCleanup}
/>,
modal
);





share|improve this answer































    0














    There should be



    export default connect(mapStateToProps, {
    setWarning
    })(WarningModal);


    This way you cen import redux connected component for rendering (in separate file) - in your version render takes original (not connected) component for mount,



    It can be done in one file but it isn't recommended.






    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%2f53417050%2freact-component-doesnt-connect-to-the-store%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      The call to connect() returns a wrapped React component constructor. This code is not using the return value of connect at all, so it's thrown away.



      The smallest change that should fix this would be to save the return value from connect in a new variable, and use that in place of WarningModal in the exported component constructor's render function:



      const WarningModalContainer = connect(mapStateToProps, {
      setWarning
      })(WarningModal);


      ...



      ReactDOM.render(
      <WarningModalContainer
      message={message}
      withCleanup={withCleanup}
      />,
      modal
      );





      share|improve this answer




























        0














        The call to connect() returns a wrapped React component constructor. This code is not using the return value of connect at all, so it's thrown away.



        The smallest change that should fix this would be to save the return value from connect in a new variable, and use that in place of WarningModal in the exported component constructor's render function:



        const WarningModalContainer = connect(mapStateToProps, {
        setWarning
        })(WarningModal);


        ...



        ReactDOM.render(
        <WarningModalContainer
        message={message}
        withCleanup={withCleanup}
        />,
        modal
        );





        share|improve this answer


























          0












          0








          0







          The call to connect() returns a wrapped React component constructor. This code is not using the return value of connect at all, so it's thrown away.



          The smallest change that should fix this would be to save the return value from connect in a new variable, and use that in place of WarningModal in the exported component constructor's render function:



          const WarningModalContainer = connect(mapStateToProps, {
          setWarning
          })(WarningModal);


          ...



          ReactDOM.render(
          <WarningModalContainer
          message={message}
          withCleanup={withCleanup}
          />,
          modal
          );





          share|improve this answer













          The call to connect() returns a wrapped React component constructor. This code is not using the return value of connect at all, so it's thrown away.



          The smallest change that should fix this would be to save the return value from connect in a new variable, and use that in place of WarningModal in the exported component constructor's render function:



          const WarningModalContainer = connect(mapStateToProps, {
          setWarning
          })(WarningModal);


          ...



          ReactDOM.render(
          <WarningModalContainer
          message={message}
          withCleanup={withCleanup}
          />,
          modal
          );






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 0:50









          stonestone

          4,68424059




          4,68424059

























              0














              There should be



              export default connect(mapStateToProps, {
              setWarning
              })(WarningModal);


              This way you cen import redux connected component for rendering (in separate file) - in your version render takes original (not connected) component for mount,



              It can be done in one file but it isn't recommended.






              share|improve this answer




























                0














                There should be



                export default connect(mapStateToProps, {
                setWarning
                })(WarningModal);


                This way you cen import redux connected component for rendering (in separate file) - in your version render takes original (not connected) component for mount,



                It can be done in one file but it isn't recommended.






                share|improve this answer


























                  0












                  0








                  0







                  There should be



                  export default connect(mapStateToProps, {
                  setWarning
                  })(WarningModal);


                  This way you cen import redux connected component for rendering (in separate file) - in your version render takes original (not connected) component for mount,



                  It can be done in one file but it isn't recommended.






                  share|improve this answer













                  There should be



                  export default connect(mapStateToProps, {
                  setWarning
                  })(WarningModal);


                  This way you cen import redux connected component for rendering (in separate file) - in your version render takes original (not connected) component for mount,



                  It can be done in one file but it isn't recommended.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 '18 at 17:17









                  xadmxadm

                  1,641258




                  1,641258






























                      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%2f53417050%2freact-component-doesnt-connect-to-the-store%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

                      Guess what letter conforming each word

                      Port of Spain

                      Run scheduled task as local user group (not BUILTIN)