Rendering a component using React Router and Redux crashing












0















I had a React app, which started to get out of hand, so I decided to go for React-Redux. It kind of went well, until I hit a weird error. It goes:



TypeError: this is undefined


And this wouldn't be nothing impressive, if it was not thrown in the React-Redux library. Like so:



PureComponent
node_modules/react/cjs/react.development.js:412

409 | */
410 |
411 | function PureComponent(props, context, updater) {
> 412 | this.props = props;
413 | ^ this.context = context; // If a component has string refs, we will assign a different object later.
414 |
415 | this.refs = emptyObject;


The console says:



The above error occurred in one of your React components:
in Unknown (created by Context.Consumer)
in Connect(Component) (at RegisterFormUI.jsx:32)
in form (at RegisterFormUI.jsx:21)
in div (at RegisterFormUI.jsx:18)
in div (at RegisterFormUI.jsx:15)
in div (at RegisterFormUI.jsx:14)
in div (at RegisterFormUI.jsx:13)
in Unknown (created by Context.Consumer)
in Connect(Component) (created by Route)
in Route (at SharedPaths.jsx:18)
in Switch (at NavigationUI.jsx:98)
in Router (created by BrowserRouter)
in BrowserRouter (at NavigationUI.jsx:65)
in Unknown (created by Context.Consumer)
in Connect(Component) (at App.js:50)
in div (at App.js:49)
in App (at src/index.js:15)
in Provider (at src/index.js:14)


which makes no sense, because I don't have a Connect method called in my RegisterFormUI component. I have no idea what I messed up. Here's my UI of the form:



export default ({user = {}}) => {
return <BrowserRouter>
<React.Fragment>
<Navbar className='navbar_all'>
<Navbar.Header>
<Navbar.Brand>
<LinkContainer className='navbar_brand' id='home' to='/'>
<NavItem>
<img alt='ZdajTo' src="assets/images/new_logo.png" style={{height: '30px'}}/>
</NavItem>
</LinkContainer>
</Navbar.Brand>
</Navbar.Header>
<Nav className='float_right'>
<LinkContainer to='/homepage' style={{textDecoration: 'none'}}>
<NavItem>
<button style={{
backgroundColor: '#F16049',
border: '4px solid #F16049',
borderRadius: '4px',
padding: '10px',
marginBottom: '5px',
color: '#fff'
}}>
DLA ROZWIĄZUJĄCYCH
</button>
</NavItem>
</LinkContainer>
</Nav>
<Nav className='float_right'>
<SharedNavBar user={user.userAcc}/>
{renderNavBar(user)}
</Nav>
</Navbar>
<Switch>
{renderPaths(user) ? renderPaths(user).map(path => path) : null}
{SharedPaths.map(path => path)}
</Switch>
</React.Fragment>
</BrowserRouter>
};


And my container is this:



import {connect} from 'react-redux';
import UI from '../../ui/studentRegistrationUI/RegisterFormUI'
import {beginRegistration} from "../../../../actions";

const mapStateToProps = state => ({user: state.user});

const mapDispatchToProps = dispatch => ({
handleClick() {
dispatch(
beginRegistration('student')
)
}
});
export default connect(mapStateToProps, mapDispatchToProps)(UI)


Any idea what I messed up?










share|improve this question



























    0















    I had a React app, which started to get out of hand, so I decided to go for React-Redux. It kind of went well, until I hit a weird error. It goes:



    TypeError: this is undefined


    And this wouldn't be nothing impressive, if it was not thrown in the React-Redux library. Like so:



    PureComponent
    node_modules/react/cjs/react.development.js:412

    409 | */
    410 |
    411 | function PureComponent(props, context, updater) {
    > 412 | this.props = props;
    413 | ^ this.context = context; // If a component has string refs, we will assign a different object later.
    414 |
    415 | this.refs = emptyObject;


    The console says:



    The above error occurred in one of your React components:
    in Unknown (created by Context.Consumer)
    in Connect(Component) (at RegisterFormUI.jsx:32)
    in form (at RegisterFormUI.jsx:21)
    in div (at RegisterFormUI.jsx:18)
    in div (at RegisterFormUI.jsx:15)
    in div (at RegisterFormUI.jsx:14)
    in div (at RegisterFormUI.jsx:13)
    in Unknown (created by Context.Consumer)
    in Connect(Component) (created by Route)
    in Route (at SharedPaths.jsx:18)
    in Switch (at NavigationUI.jsx:98)
    in Router (created by BrowserRouter)
    in BrowserRouter (at NavigationUI.jsx:65)
    in Unknown (created by Context.Consumer)
    in Connect(Component) (at App.js:50)
    in div (at App.js:49)
    in App (at src/index.js:15)
    in Provider (at src/index.js:14)


    which makes no sense, because I don't have a Connect method called in my RegisterFormUI component. I have no idea what I messed up. Here's my UI of the form:



    export default ({user = {}}) => {
    return <BrowserRouter>
    <React.Fragment>
    <Navbar className='navbar_all'>
    <Navbar.Header>
    <Navbar.Brand>
    <LinkContainer className='navbar_brand' id='home' to='/'>
    <NavItem>
    <img alt='ZdajTo' src="assets/images/new_logo.png" style={{height: '30px'}}/>
    </NavItem>
    </LinkContainer>
    </Navbar.Brand>
    </Navbar.Header>
    <Nav className='float_right'>
    <LinkContainer to='/homepage' style={{textDecoration: 'none'}}>
    <NavItem>
    <button style={{
    backgroundColor: '#F16049',
    border: '4px solid #F16049',
    borderRadius: '4px',
    padding: '10px',
    marginBottom: '5px',
    color: '#fff'
    }}>
    DLA ROZWIĄZUJĄCYCH
    </button>
    </NavItem>
    </LinkContainer>
    </Nav>
    <Nav className='float_right'>
    <SharedNavBar user={user.userAcc}/>
    {renderNavBar(user)}
    </Nav>
    </Navbar>
    <Switch>
    {renderPaths(user) ? renderPaths(user).map(path => path) : null}
    {SharedPaths.map(path => path)}
    </Switch>
    </React.Fragment>
    </BrowserRouter>
    };


    And my container is this:



    import {connect} from 'react-redux';
    import UI from '../../ui/studentRegistrationUI/RegisterFormUI'
    import {beginRegistration} from "../../../../actions";

    const mapStateToProps = state => ({user: state.user});

    const mapDispatchToProps = dispatch => ({
    handleClick() {
    dispatch(
    beginRegistration('student')
    )
    }
    });
    export default connect(mapStateToProps, mapDispatchToProps)(UI)


    Any idea what I messed up?










    share|improve this question

























      0












      0








      0








      I had a React app, which started to get out of hand, so I decided to go for React-Redux. It kind of went well, until I hit a weird error. It goes:



      TypeError: this is undefined


      And this wouldn't be nothing impressive, if it was not thrown in the React-Redux library. Like so:



      PureComponent
      node_modules/react/cjs/react.development.js:412

      409 | */
      410 |
      411 | function PureComponent(props, context, updater) {
      > 412 | this.props = props;
      413 | ^ this.context = context; // If a component has string refs, we will assign a different object later.
      414 |
      415 | this.refs = emptyObject;


      The console says:



      The above error occurred in one of your React components:
      in Unknown (created by Context.Consumer)
      in Connect(Component) (at RegisterFormUI.jsx:32)
      in form (at RegisterFormUI.jsx:21)
      in div (at RegisterFormUI.jsx:18)
      in div (at RegisterFormUI.jsx:15)
      in div (at RegisterFormUI.jsx:14)
      in div (at RegisterFormUI.jsx:13)
      in Unknown (created by Context.Consumer)
      in Connect(Component) (created by Route)
      in Route (at SharedPaths.jsx:18)
      in Switch (at NavigationUI.jsx:98)
      in Router (created by BrowserRouter)
      in BrowserRouter (at NavigationUI.jsx:65)
      in Unknown (created by Context.Consumer)
      in Connect(Component) (at App.js:50)
      in div (at App.js:49)
      in App (at src/index.js:15)
      in Provider (at src/index.js:14)


      which makes no sense, because I don't have a Connect method called in my RegisterFormUI component. I have no idea what I messed up. Here's my UI of the form:



      export default ({user = {}}) => {
      return <BrowserRouter>
      <React.Fragment>
      <Navbar className='navbar_all'>
      <Navbar.Header>
      <Navbar.Brand>
      <LinkContainer className='navbar_brand' id='home' to='/'>
      <NavItem>
      <img alt='ZdajTo' src="assets/images/new_logo.png" style={{height: '30px'}}/>
      </NavItem>
      </LinkContainer>
      </Navbar.Brand>
      </Navbar.Header>
      <Nav className='float_right'>
      <LinkContainer to='/homepage' style={{textDecoration: 'none'}}>
      <NavItem>
      <button style={{
      backgroundColor: '#F16049',
      border: '4px solid #F16049',
      borderRadius: '4px',
      padding: '10px',
      marginBottom: '5px',
      color: '#fff'
      }}>
      DLA ROZWIĄZUJĄCYCH
      </button>
      </NavItem>
      </LinkContainer>
      </Nav>
      <Nav className='float_right'>
      <SharedNavBar user={user.userAcc}/>
      {renderNavBar(user)}
      </Nav>
      </Navbar>
      <Switch>
      {renderPaths(user) ? renderPaths(user).map(path => path) : null}
      {SharedPaths.map(path => path)}
      </Switch>
      </React.Fragment>
      </BrowserRouter>
      };


      And my container is this:



      import {connect} from 'react-redux';
      import UI from '../../ui/studentRegistrationUI/RegisterFormUI'
      import {beginRegistration} from "../../../../actions";

      const mapStateToProps = state => ({user: state.user});

      const mapDispatchToProps = dispatch => ({
      handleClick() {
      dispatch(
      beginRegistration('student')
      )
      }
      });
      export default connect(mapStateToProps, mapDispatchToProps)(UI)


      Any idea what I messed up?










      share|improve this question














      I had a React app, which started to get out of hand, so I decided to go for React-Redux. It kind of went well, until I hit a weird error. It goes:



      TypeError: this is undefined


      And this wouldn't be nothing impressive, if it was not thrown in the React-Redux library. Like so:



      PureComponent
      node_modules/react/cjs/react.development.js:412

      409 | */
      410 |
      411 | function PureComponent(props, context, updater) {
      > 412 | this.props = props;
      413 | ^ this.context = context; // If a component has string refs, we will assign a different object later.
      414 |
      415 | this.refs = emptyObject;


      The console says:



      The above error occurred in one of your React components:
      in Unknown (created by Context.Consumer)
      in Connect(Component) (at RegisterFormUI.jsx:32)
      in form (at RegisterFormUI.jsx:21)
      in div (at RegisterFormUI.jsx:18)
      in div (at RegisterFormUI.jsx:15)
      in div (at RegisterFormUI.jsx:14)
      in div (at RegisterFormUI.jsx:13)
      in Unknown (created by Context.Consumer)
      in Connect(Component) (created by Route)
      in Route (at SharedPaths.jsx:18)
      in Switch (at NavigationUI.jsx:98)
      in Router (created by BrowserRouter)
      in BrowserRouter (at NavigationUI.jsx:65)
      in Unknown (created by Context.Consumer)
      in Connect(Component) (at App.js:50)
      in div (at App.js:49)
      in App (at src/index.js:15)
      in Provider (at src/index.js:14)


      which makes no sense, because I don't have a Connect method called in my RegisterFormUI component. I have no idea what I messed up. Here's my UI of the form:



      export default ({user = {}}) => {
      return <BrowserRouter>
      <React.Fragment>
      <Navbar className='navbar_all'>
      <Navbar.Header>
      <Navbar.Brand>
      <LinkContainer className='navbar_brand' id='home' to='/'>
      <NavItem>
      <img alt='ZdajTo' src="assets/images/new_logo.png" style={{height: '30px'}}/>
      </NavItem>
      </LinkContainer>
      </Navbar.Brand>
      </Navbar.Header>
      <Nav className='float_right'>
      <LinkContainer to='/homepage' style={{textDecoration: 'none'}}>
      <NavItem>
      <button style={{
      backgroundColor: '#F16049',
      border: '4px solid #F16049',
      borderRadius: '4px',
      padding: '10px',
      marginBottom: '5px',
      color: '#fff'
      }}>
      DLA ROZWIĄZUJĄCYCH
      </button>
      </NavItem>
      </LinkContainer>
      </Nav>
      <Nav className='float_right'>
      <SharedNavBar user={user.userAcc}/>
      {renderNavBar(user)}
      </Nav>
      </Navbar>
      <Switch>
      {renderPaths(user) ? renderPaths(user).map(path => path) : null}
      {SharedPaths.map(path => path)}
      </Switch>
      </React.Fragment>
      </BrowserRouter>
      };


      And my container is this:



      import {connect} from 'react-redux';
      import UI from '../../ui/studentRegistrationUI/RegisterFormUI'
      import {beginRegistration} from "../../../../actions";

      const mapStateToProps = state => ({user: state.user});

      const mapDispatchToProps = dispatch => ({
      handleClick() {
      dispatch(
      beginRegistration('student')
      )
      }
      });
      export default connect(mapStateToProps, mapDispatchToProps)(UI)


      Any idea what I messed up?







      javascript reactjs redux react-redux






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 15:14









      Alex IronsideAlex Ironside

      1,093829




      1,093829
























          1 Answer
          1






          active

          oldest

          votes


















          0














          There was a problem with one of my children components. Mainly I tried to do this:



          {CheckBox('Regulations', '/assets/regulamin.pdf', 'regulamin')}


          And I should've done this:



          <CheckBox id={'Regulations'} path={'/assets/regulamin.pdf'} text={'regulamin'}/>


          And here's the container for future reference:



          import {connect} from 'react-redux';
          import UI from '../../../ui/studentRegistrationUI/components/CheckBoxUI'

          const mapStateToProps = (state, props) => ({user: state.user, id: props.id, path: props.path, text: props.text});

          export default connect(mapStateToProps)(UI)





          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%2f54008755%2frendering-a-component-using-react-router-and-redux-crashing%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









            0














            There was a problem with one of my children components. Mainly I tried to do this:



            {CheckBox('Regulations', '/assets/regulamin.pdf', 'regulamin')}


            And I should've done this:



            <CheckBox id={'Regulations'} path={'/assets/regulamin.pdf'} text={'regulamin'}/>


            And here's the container for future reference:



            import {connect} from 'react-redux';
            import UI from '../../../ui/studentRegistrationUI/components/CheckBoxUI'

            const mapStateToProps = (state, props) => ({user: state.user, id: props.id, path: props.path, text: props.text});

            export default connect(mapStateToProps)(UI)





            share|improve this answer




























              0














              There was a problem with one of my children components. Mainly I tried to do this:



              {CheckBox('Regulations', '/assets/regulamin.pdf', 'regulamin')}


              And I should've done this:



              <CheckBox id={'Regulations'} path={'/assets/regulamin.pdf'} text={'regulamin'}/>


              And here's the container for future reference:



              import {connect} from 'react-redux';
              import UI from '../../../ui/studentRegistrationUI/components/CheckBoxUI'

              const mapStateToProps = (state, props) => ({user: state.user, id: props.id, path: props.path, text: props.text});

              export default connect(mapStateToProps)(UI)





              share|improve this answer


























                0












                0








                0







                There was a problem with one of my children components. Mainly I tried to do this:



                {CheckBox('Regulations', '/assets/regulamin.pdf', 'regulamin')}


                And I should've done this:



                <CheckBox id={'Regulations'} path={'/assets/regulamin.pdf'} text={'regulamin'}/>


                And here's the container for future reference:



                import {connect} from 'react-redux';
                import UI from '../../../ui/studentRegistrationUI/components/CheckBoxUI'

                const mapStateToProps = (state, props) => ({user: state.user, id: props.id, path: props.path, text: props.text});

                export default connect(mapStateToProps)(UI)





                share|improve this answer













                There was a problem with one of my children components. Mainly I tried to do this:



                {CheckBox('Regulations', '/assets/regulamin.pdf', 'regulamin')}


                And I should've done this:



                <CheckBox id={'Regulations'} path={'/assets/regulamin.pdf'} text={'regulamin'}/>


                And here's the container for future reference:



                import {connect} from 'react-redux';
                import UI from '../../../ui/studentRegistrationUI/components/CheckBoxUI'

                const mapStateToProps = (state, props) => ({user: state.user, id: props.id, path: props.path, text: props.text});

                export default connect(mapStateToProps)(UI)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 3 at 9:26









                Alex IronsideAlex Ironside

                1,093829




                1,093829
































                    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%2f54008755%2frendering-a-component-using-react-router-and-redux-crashing%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

                    android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                    SQL update select statement

                    WPF add header to Image with URL pettitions [duplicate]