React undefined setState from propsDetecting an undefined object propertyHow to check empty/undefined/null string in JavaScript?How do I remove a property from a JavaScript object?How to determine if variable is 'undefined' or 'null'?How to check for “undefined” in JavaScript?Is there a standard function to check for null, undefined, or blank variables in JavaScript?How do I remove a particular element from an array in JavaScript?.prop() vs .attr()How do I return the response from an asynchronous call?Loop inside React JSX

Is my low blitz game drawing rate at www.chess.com an indicator that I am weak in chess?

What does Apple's new App Store requirement mean

A variation to the phrase "hanging over my shoulders"

Is this part of the description of the Archfey warlock's Misty Escape feature redundant?

Why does Carol not get rid of the Kree symbol on her suit when she changes its colours?

Why is so much work done on numerical verification of the Riemann Hypothesis?

Will number of steps recorded on FitBit/any fitness tracker add up distance in PokemonGo?

Taxes on Dividends in a Roth IRA

Stack Interview Code methods made from class Node and Smart Pointers

How to preserve electronics (computers, iPads and phones) for hundreds of years

What is the English pronunciation of "pain au chocolat"?

What kind of floor tile is this?

Permission on Database

What is going on with gets(stdin) on the site coderbyte?

Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?

When were female captains banned from Starfleet?

Why Shazam when there is already Superman?

How do I tell my boss that I'm quitting soon, especially given that a colleague just left this week

What to do when eye contact makes your coworker uncomfortable?

Is it necessary to use pronouns with the verb "essere"?

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?

Can I say "fingers" when referring to toes?

Microchip documentation does not label CAN buss pins on micro controller pinout diagram

Creating two special characters



React undefined setState from props


Detecting an undefined object propertyHow to check empty/undefined/null string in JavaScript?How do I remove a property from a JavaScript object?How to determine if variable is 'undefined' or 'null'?How to check for “undefined” in JavaScript?Is there a standard function to check for null, undefined, or blank variables in JavaScript?How do I remove a particular element from an array in JavaScript?.prop() vs .attr()How do I return the response from an asynchronous call?Loop inside React JSX













0















I've two componentes: Orders and FormDialog, the first is father of the second.
I've trying to send data as properties from Orders to FormDialog as follows:




Orders Component




class Orders extends Component {
state=
open: false,
order:
address: '',
client: '',
date: '',
estimated_time: '',
id: 0,
order_no: '',
original_order_no: '',
phone: '',
place: '',
position: '',
status: '',
team: ''


render()
return (
<div>
<FormDialog open=this.state.open order=this.state.order/>
</div>
);




FormDialog Component




export default class FormDialog extends React.Component 

constructor(...props)
super(...props);
this.state =
order:
address: '',
client: '',
date: '',
estimated_time: '',
id: 0,
order_no: '',
original_order_no: '',
phone: '',
place: '',
position: '',
status: '',
team: ''

;

async componentWillMount()
this.setState(order: this.props.order)
;
render()
return (
<div>this.state.order.team</div>
)


This display TypeError: this.state.order is undefined when try to compile. Any suggestion?










share|improve this question




























    0















    I've two componentes: Orders and FormDialog, the first is father of the second.
    I've trying to send data as properties from Orders to FormDialog as follows:




    Orders Component




    class Orders extends Component {
    state=
    open: false,
    order:
    address: '',
    client: '',
    date: '',
    estimated_time: '',
    id: 0,
    order_no: '',
    original_order_no: '',
    phone: '',
    place: '',
    position: '',
    status: '',
    team: ''


    render()
    return (
    <div>
    <FormDialog open=this.state.open order=this.state.order/>
    </div>
    );




    FormDialog Component




    export default class FormDialog extends React.Component 

    constructor(...props)
    super(...props);
    this.state =
    order:
    address: '',
    client: '',
    date: '',
    estimated_time: '',
    id: 0,
    order_no: '',
    original_order_no: '',
    phone: '',
    place: '',
    position: '',
    status: '',
    team: ''

    ;

    async componentWillMount()
    this.setState(order: this.props.order)
    ;
    render()
    return (
    <div>this.state.order.team</div>
    )


    This display TypeError: this.state.order is undefined when try to compile. Any suggestion?










    share|improve this question


























      0












      0








      0


      0






      I've two componentes: Orders and FormDialog, the first is father of the second.
      I've trying to send data as properties from Orders to FormDialog as follows:




      Orders Component




      class Orders extends Component {
      state=
      open: false,
      order:
      address: '',
      client: '',
      date: '',
      estimated_time: '',
      id: 0,
      order_no: '',
      original_order_no: '',
      phone: '',
      place: '',
      position: '',
      status: '',
      team: ''


      render()
      return (
      <div>
      <FormDialog open=this.state.open order=this.state.order/>
      </div>
      );




      FormDialog Component




      export default class FormDialog extends React.Component 

      constructor(...props)
      super(...props);
      this.state =
      order:
      address: '',
      client: '',
      date: '',
      estimated_time: '',
      id: 0,
      order_no: '',
      original_order_no: '',
      phone: '',
      place: '',
      position: '',
      status: '',
      team: ''

      ;

      async componentWillMount()
      this.setState(order: this.props.order)
      ;
      render()
      return (
      <div>this.state.order.team</div>
      )


      This display TypeError: this.state.order is undefined when try to compile. Any suggestion?










      share|improve this question
















      I've two componentes: Orders and FormDialog, the first is father of the second.
      I've trying to send data as properties from Orders to FormDialog as follows:




      Orders Component




      class Orders extends Component {
      state=
      open: false,
      order:
      address: '',
      client: '',
      date: '',
      estimated_time: '',
      id: 0,
      order_no: '',
      original_order_no: '',
      phone: '',
      place: '',
      position: '',
      status: '',
      team: ''


      render()
      return (
      <div>
      <FormDialog open=this.state.open order=this.state.order/>
      </div>
      );




      FormDialog Component




      export default class FormDialog extends React.Component 

      constructor(...props)
      super(...props);
      this.state =
      order:
      address: '',
      client: '',
      date: '',
      estimated_time: '',
      id: 0,
      order_no: '',
      original_order_no: '',
      phone: '',
      place: '',
      position: '',
      status: '',
      team: ''

      ;

      async componentWillMount()
      this.setState(order: this.props.order)
      ;
      render()
      return (
      <div>this.state.order.team</div>
      )


      This display TypeError: this.state.order is undefined when try to compile. Any suggestion?







      javascript reactjs react-props react-state






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 12:20









      ToneCrate

      30539




      30539










      asked Mar 7 at 23:49









      Raul Castro RiveroRaul Castro Rivero

      85




      85






















          3 Answers
          3






          active

          oldest

          votes


















          2














          Two issues:




          1. Your render method is trying to render a FormDialog using state which isn't initialized yet. State will be undefined until you set it inside constructor like:



            constructor(props) 
            super(props);

            this.state =
            order: this.props.order,




          Since you're just passing down a prop from the parent component, this will be enough to render the component without errors. This way you don't need to call componentDidMount or, in your case, componentWillMount, and can remove it altogether.




          1. You're calling setState in an unmounted component, which will always result in an error in React. As its name suggests, componentWillMount is called right before the component mounts and you should be using componentDidMount instead to make sure the component is mounted before calling setState.

          Also, componentWillMount has been deprecated in newer versions of React and is no longer recommended to be used in code.



          From React official documentation




          Additional note, it seems to me that you have unnecessary duplication of state in these two components. Consider keeping the order data only in the FormDialog component since it will probably be the only component updating order data.






          share|improve this answer

























          • Sorry, it was an example, only the second component has that state the first just send the object.

            – Raul Castro Rivero
            Mar 8 at 0:49











          • You're absolutely right, that's a doubt I had some time ago but unfortunately it does not fix my bug, it keeps showing me TypeError: this.state.order is undefined

            – Raul Castro Rivero
            Mar 8 at 0:55











          • I've updated my answer, please take a look, it should solve your current problem

            – ToneCrate
            Mar 8 at 2:36











          • Thanks for the answers and the help but it does not work, at least for me :). I think I'll have to change the structure and put it as a stateless component. Thank you anyway.

            – Raul Castro Rivero
            Mar 8 at 7:09











          • Then it seems you're not passing order properly to the child component, try console.log(this.props.order) in the constructor to make sure it's not undefined.

            – ToneCrate
            Mar 8 at 11:24


















          1














          super(props), not super( ...props)
          same for constructor



          This link to the doc shows the proper way



          https://reactjs.org/docs/react-component.html#constructor



          Just after the constructor, the code is still correct but after componentWillMount state.order is replaced by this.props.order which is not initialised due to the first error.






          share|improve this answer

























          • How does that explain the error though?

            – Felix Kling
            Mar 8 at 0:02











          • I've changed ...props with props but it display the same.

            – Raul Castro Rivero
            Mar 8 at 0:05











          • Bruno, perhaps add some color to the answer.

            – Bibberty
            Mar 8 at 0:08











          • I updated my answer. Sorry my first answer :) will need more practice for colors

            – Bruno Winck
            Mar 8 at 0:11


















          0














          You should avoid state duplication, you can make FormDialog stateless component, maybe even function component. Remember to use as many stateless component as possible.



          import React from 'react';

          const FormDialog = props =>
          return (
          <div>
          props.order.team
          </div>
          );
          ;

          export default FormDialog;


          Regardless, it looks like your TypeError error appears because you



          (1) Typo, it should be a



          constructor (props) 
          super (props);
          this.state = bla bla bla ...;



          or just



          state= bla bla bla ... 


          like you did in Orders component



          (2) Tried calling setstate before the component mounted. Change async componentWillMount() to componentDidMount() should works.



          But don't worry about that, after you change the component to function component it shouldn't appear.






          share|improve this answer























          • Thank you for your answer but I can not make it a stateless component because as its name indicates it is a form and I have to access that data and a method to save the form in the backend, I do not know if you understand me?

            – Raul Castro Rivero
            Mar 8 at 1:34











          • is the error still appear after you fix your typo and change componentWillMount ?

            – Jatmiko Herjati
            Mar 8 at 2:07











          • Exactly, the error lasts!

            – Raul Castro Rivero
            Mar 8 at 2:12










          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%2f55054643%2freact-undefined-setstate-from-props%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














          Two issues:




          1. Your render method is trying to render a FormDialog using state which isn't initialized yet. State will be undefined until you set it inside constructor like:



            constructor(props) 
            super(props);

            this.state =
            order: this.props.order,




          Since you're just passing down a prop from the parent component, this will be enough to render the component without errors. This way you don't need to call componentDidMount or, in your case, componentWillMount, and can remove it altogether.




          1. You're calling setState in an unmounted component, which will always result in an error in React. As its name suggests, componentWillMount is called right before the component mounts and you should be using componentDidMount instead to make sure the component is mounted before calling setState.

          Also, componentWillMount has been deprecated in newer versions of React and is no longer recommended to be used in code.



          From React official documentation




          Additional note, it seems to me that you have unnecessary duplication of state in these two components. Consider keeping the order data only in the FormDialog component since it will probably be the only component updating order data.






          share|improve this answer

























          • Sorry, it was an example, only the second component has that state the first just send the object.

            – Raul Castro Rivero
            Mar 8 at 0:49











          • You're absolutely right, that's a doubt I had some time ago but unfortunately it does not fix my bug, it keeps showing me TypeError: this.state.order is undefined

            – Raul Castro Rivero
            Mar 8 at 0:55











          • I've updated my answer, please take a look, it should solve your current problem

            – ToneCrate
            Mar 8 at 2:36











          • Thanks for the answers and the help but it does not work, at least for me :). I think I'll have to change the structure and put it as a stateless component. Thank you anyway.

            – Raul Castro Rivero
            Mar 8 at 7:09











          • Then it seems you're not passing order properly to the child component, try console.log(this.props.order) in the constructor to make sure it's not undefined.

            – ToneCrate
            Mar 8 at 11:24















          2














          Two issues:




          1. Your render method is trying to render a FormDialog using state which isn't initialized yet. State will be undefined until you set it inside constructor like:



            constructor(props) 
            super(props);

            this.state =
            order: this.props.order,




          Since you're just passing down a prop from the parent component, this will be enough to render the component without errors. This way you don't need to call componentDidMount or, in your case, componentWillMount, and can remove it altogether.




          1. You're calling setState in an unmounted component, which will always result in an error in React. As its name suggests, componentWillMount is called right before the component mounts and you should be using componentDidMount instead to make sure the component is mounted before calling setState.

          Also, componentWillMount has been deprecated in newer versions of React and is no longer recommended to be used in code.



          From React official documentation




          Additional note, it seems to me that you have unnecessary duplication of state in these two components. Consider keeping the order data only in the FormDialog component since it will probably be the only component updating order data.






          share|improve this answer

























          • Sorry, it was an example, only the second component has that state the first just send the object.

            – Raul Castro Rivero
            Mar 8 at 0:49











          • You're absolutely right, that's a doubt I had some time ago but unfortunately it does not fix my bug, it keeps showing me TypeError: this.state.order is undefined

            – Raul Castro Rivero
            Mar 8 at 0:55











          • I've updated my answer, please take a look, it should solve your current problem

            – ToneCrate
            Mar 8 at 2:36











          • Thanks for the answers and the help but it does not work, at least for me :). I think I'll have to change the structure and put it as a stateless component. Thank you anyway.

            – Raul Castro Rivero
            Mar 8 at 7:09











          • Then it seems you're not passing order properly to the child component, try console.log(this.props.order) in the constructor to make sure it's not undefined.

            – ToneCrate
            Mar 8 at 11:24













          2












          2








          2







          Two issues:




          1. Your render method is trying to render a FormDialog using state which isn't initialized yet. State will be undefined until you set it inside constructor like:



            constructor(props) 
            super(props);

            this.state =
            order: this.props.order,




          Since you're just passing down a prop from the parent component, this will be enough to render the component without errors. This way you don't need to call componentDidMount or, in your case, componentWillMount, and can remove it altogether.




          1. You're calling setState in an unmounted component, which will always result in an error in React. As its name suggests, componentWillMount is called right before the component mounts and you should be using componentDidMount instead to make sure the component is mounted before calling setState.

          Also, componentWillMount has been deprecated in newer versions of React and is no longer recommended to be used in code.



          From React official documentation




          Additional note, it seems to me that you have unnecessary duplication of state in these two components. Consider keeping the order data only in the FormDialog component since it will probably be the only component updating order data.






          share|improve this answer















          Two issues:




          1. Your render method is trying to render a FormDialog using state which isn't initialized yet. State will be undefined until you set it inside constructor like:



            constructor(props) 
            super(props);

            this.state =
            order: this.props.order,




          Since you're just passing down a prop from the parent component, this will be enough to render the component without errors. This way you don't need to call componentDidMount or, in your case, componentWillMount, and can remove it altogether.




          1. You're calling setState in an unmounted component, which will always result in an error in React. As its name suggests, componentWillMount is called right before the component mounts and you should be using componentDidMount instead to make sure the component is mounted before calling setState.

          Also, componentWillMount has been deprecated in newer versions of React and is no longer recommended to be used in code.



          From React official documentation




          Additional note, it seems to me that you have unnecessary duplication of state in these two components. Consider keeping the order data only in the FormDialog component since it will probably be the only component updating order data.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 16 at 17:21

























          answered Mar 8 at 0:12









          ToneCrateToneCrate

          30539




          30539












          • Sorry, it was an example, only the second component has that state the first just send the object.

            – Raul Castro Rivero
            Mar 8 at 0:49











          • You're absolutely right, that's a doubt I had some time ago but unfortunately it does not fix my bug, it keeps showing me TypeError: this.state.order is undefined

            – Raul Castro Rivero
            Mar 8 at 0:55











          • I've updated my answer, please take a look, it should solve your current problem

            – ToneCrate
            Mar 8 at 2:36











          • Thanks for the answers and the help but it does not work, at least for me :). I think I'll have to change the structure and put it as a stateless component. Thank you anyway.

            – Raul Castro Rivero
            Mar 8 at 7:09











          • Then it seems you're not passing order properly to the child component, try console.log(this.props.order) in the constructor to make sure it's not undefined.

            – ToneCrate
            Mar 8 at 11:24

















          • Sorry, it was an example, only the second component has that state the first just send the object.

            – Raul Castro Rivero
            Mar 8 at 0:49











          • You're absolutely right, that's a doubt I had some time ago but unfortunately it does not fix my bug, it keeps showing me TypeError: this.state.order is undefined

            – Raul Castro Rivero
            Mar 8 at 0:55











          • I've updated my answer, please take a look, it should solve your current problem

            – ToneCrate
            Mar 8 at 2:36











          • Thanks for the answers and the help but it does not work, at least for me :). I think I'll have to change the structure and put it as a stateless component. Thank you anyway.

            – Raul Castro Rivero
            Mar 8 at 7:09











          • Then it seems you're not passing order properly to the child component, try console.log(this.props.order) in the constructor to make sure it's not undefined.

            – ToneCrate
            Mar 8 at 11:24
















          Sorry, it was an example, only the second component has that state the first just send the object.

          – Raul Castro Rivero
          Mar 8 at 0:49





          Sorry, it was an example, only the second component has that state the first just send the object.

          – Raul Castro Rivero
          Mar 8 at 0:49













          You're absolutely right, that's a doubt I had some time ago but unfortunately it does not fix my bug, it keeps showing me TypeError: this.state.order is undefined

          – Raul Castro Rivero
          Mar 8 at 0:55





          You're absolutely right, that's a doubt I had some time ago but unfortunately it does not fix my bug, it keeps showing me TypeError: this.state.order is undefined

          – Raul Castro Rivero
          Mar 8 at 0:55













          I've updated my answer, please take a look, it should solve your current problem

          – ToneCrate
          Mar 8 at 2:36





          I've updated my answer, please take a look, it should solve your current problem

          – ToneCrate
          Mar 8 at 2:36













          Thanks for the answers and the help but it does not work, at least for me :). I think I'll have to change the structure and put it as a stateless component. Thank you anyway.

          – Raul Castro Rivero
          Mar 8 at 7:09





          Thanks for the answers and the help but it does not work, at least for me :). I think I'll have to change the structure and put it as a stateless component. Thank you anyway.

          – Raul Castro Rivero
          Mar 8 at 7:09













          Then it seems you're not passing order properly to the child component, try console.log(this.props.order) in the constructor to make sure it's not undefined.

          – ToneCrate
          Mar 8 at 11:24





          Then it seems you're not passing order properly to the child component, try console.log(this.props.order) in the constructor to make sure it's not undefined.

          – ToneCrate
          Mar 8 at 11:24













          1














          super(props), not super( ...props)
          same for constructor



          This link to the doc shows the proper way



          https://reactjs.org/docs/react-component.html#constructor



          Just after the constructor, the code is still correct but after componentWillMount state.order is replaced by this.props.order which is not initialised due to the first error.






          share|improve this answer

























          • How does that explain the error though?

            – Felix Kling
            Mar 8 at 0:02











          • I've changed ...props with props but it display the same.

            – Raul Castro Rivero
            Mar 8 at 0:05











          • Bruno, perhaps add some color to the answer.

            – Bibberty
            Mar 8 at 0:08











          • I updated my answer. Sorry my first answer :) will need more practice for colors

            – Bruno Winck
            Mar 8 at 0:11















          1














          super(props), not super( ...props)
          same for constructor



          This link to the doc shows the proper way



          https://reactjs.org/docs/react-component.html#constructor



          Just after the constructor, the code is still correct but after componentWillMount state.order is replaced by this.props.order which is not initialised due to the first error.






          share|improve this answer

























          • How does that explain the error though?

            – Felix Kling
            Mar 8 at 0:02











          • I've changed ...props with props but it display the same.

            – Raul Castro Rivero
            Mar 8 at 0:05











          • Bruno, perhaps add some color to the answer.

            – Bibberty
            Mar 8 at 0:08











          • I updated my answer. Sorry my first answer :) will need more practice for colors

            – Bruno Winck
            Mar 8 at 0:11













          1












          1








          1







          super(props), not super( ...props)
          same for constructor



          This link to the doc shows the proper way



          https://reactjs.org/docs/react-component.html#constructor



          Just after the constructor, the code is still correct but after componentWillMount state.order is replaced by this.props.order which is not initialised due to the first error.






          share|improve this answer















          super(props), not super( ...props)
          same for constructor



          This link to the doc shows the proper way



          https://reactjs.org/docs/react-component.html#constructor



          Just after the constructor, the code is still correct but after componentWillMount state.order is replaced by this.props.order which is not initialised due to the first error.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 8 at 0:10

























          answered Mar 8 at 0:00









          Bruno WinckBruno Winck

          112




          112












          • How does that explain the error though?

            – Felix Kling
            Mar 8 at 0:02











          • I've changed ...props with props but it display the same.

            – Raul Castro Rivero
            Mar 8 at 0:05











          • Bruno, perhaps add some color to the answer.

            – Bibberty
            Mar 8 at 0:08











          • I updated my answer. Sorry my first answer :) will need more practice for colors

            – Bruno Winck
            Mar 8 at 0:11

















          • How does that explain the error though?

            – Felix Kling
            Mar 8 at 0:02











          • I've changed ...props with props but it display the same.

            – Raul Castro Rivero
            Mar 8 at 0:05











          • Bruno, perhaps add some color to the answer.

            – Bibberty
            Mar 8 at 0:08











          • I updated my answer. Sorry my first answer :) will need more practice for colors

            – Bruno Winck
            Mar 8 at 0:11
















          How does that explain the error though?

          – Felix Kling
          Mar 8 at 0:02





          How does that explain the error though?

          – Felix Kling
          Mar 8 at 0:02













          I've changed ...props with props but it display the same.

          – Raul Castro Rivero
          Mar 8 at 0:05





          I've changed ...props with props but it display the same.

          – Raul Castro Rivero
          Mar 8 at 0:05













          Bruno, perhaps add some color to the answer.

          – Bibberty
          Mar 8 at 0:08





          Bruno, perhaps add some color to the answer.

          – Bibberty
          Mar 8 at 0:08













          I updated my answer. Sorry my first answer :) will need more practice for colors

          – Bruno Winck
          Mar 8 at 0:11





          I updated my answer. Sorry my first answer :) will need more practice for colors

          – Bruno Winck
          Mar 8 at 0:11











          0














          You should avoid state duplication, you can make FormDialog stateless component, maybe even function component. Remember to use as many stateless component as possible.



          import React from 'react';

          const FormDialog = props =>
          return (
          <div>
          props.order.team
          </div>
          );
          ;

          export default FormDialog;


          Regardless, it looks like your TypeError error appears because you



          (1) Typo, it should be a



          constructor (props) 
          super (props);
          this.state = bla bla bla ...;



          or just



          state= bla bla bla ... 


          like you did in Orders component



          (2) Tried calling setstate before the component mounted. Change async componentWillMount() to componentDidMount() should works.



          But don't worry about that, after you change the component to function component it shouldn't appear.






          share|improve this answer























          • Thank you for your answer but I can not make it a stateless component because as its name indicates it is a form and I have to access that data and a method to save the form in the backend, I do not know if you understand me?

            – Raul Castro Rivero
            Mar 8 at 1:34











          • is the error still appear after you fix your typo and change componentWillMount ?

            – Jatmiko Herjati
            Mar 8 at 2:07











          • Exactly, the error lasts!

            – Raul Castro Rivero
            Mar 8 at 2:12















          0














          You should avoid state duplication, you can make FormDialog stateless component, maybe even function component. Remember to use as many stateless component as possible.



          import React from 'react';

          const FormDialog = props =>
          return (
          <div>
          props.order.team
          </div>
          );
          ;

          export default FormDialog;


          Regardless, it looks like your TypeError error appears because you



          (1) Typo, it should be a



          constructor (props) 
          super (props);
          this.state = bla bla bla ...;



          or just



          state= bla bla bla ... 


          like you did in Orders component



          (2) Tried calling setstate before the component mounted. Change async componentWillMount() to componentDidMount() should works.



          But don't worry about that, after you change the component to function component it shouldn't appear.






          share|improve this answer























          • Thank you for your answer but I can not make it a stateless component because as its name indicates it is a form and I have to access that data and a method to save the form in the backend, I do not know if you understand me?

            – Raul Castro Rivero
            Mar 8 at 1:34











          • is the error still appear after you fix your typo and change componentWillMount ?

            – Jatmiko Herjati
            Mar 8 at 2:07











          • Exactly, the error lasts!

            – Raul Castro Rivero
            Mar 8 at 2:12













          0












          0








          0







          You should avoid state duplication, you can make FormDialog stateless component, maybe even function component. Remember to use as many stateless component as possible.



          import React from 'react';

          const FormDialog = props =>
          return (
          <div>
          props.order.team
          </div>
          );
          ;

          export default FormDialog;


          Regardless, it looks like your TypeError error appears because you



          (1) Typo, it should be a



          constructor (props) 
          super (props);
          this.state = bla bla bla ...;



          or just



          state= bla bla bla ... 


          like you did in Orders component



          (2) Tried calling setstate before the component mounted. Change async componentWillMount() to componentDidMount() should works.



          But don't worry about that, after you change the component to function component it shouldn't appear.






          share|improve this answer













          You should avoid state duplication, you can make FormDialog stateless component, maybe even function component. Remember to use as many stateless component as possible.



          import React from 'react';

          const FormDialog = props =>
          return (
          <div>
          props.order.team
          </div>
          );
          ;

          export default FormDialog;


          Regardless, it looks like your TypeError error appears because you



          (1) Typo, it should be a



          constructor (props) 
          super (props);
          this.state = bla bla bla ...;



          or just



          state= bla bla bla ... 


          like you did in Orders component



          (2) Tried calling setstate before the component mounted. Change async componentWillMount() to componentDidMount() should works.



          But don't worry about that, after you change the component to function component it shouldn't appear.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 1:11









          Jatmiko HerjatiJatmiko Herjati

          92




          92












          • Thank you for your answer but I can not make it a stateless component because as its name indicates it is a form and I have to access that data and a method to save the form in the backend, I do not know if you understand me?

            – Raul Castro Rivero
            Mar 8 at 1:34











          • is the error still appear after you fix your typo and change componentWillMount ?

            – Jatmiko Herjati
            Mar 8 at 2:07











          • Exactly, the error lasts!

            – Raul Castro Rivero
            Mar 8 at 2:12

















          • Thank you for your answer but I can not make it a stateless component because as its name indicates it is a form and I have to access that data and a method to save the form in the backend, I do not know if you understand me?

            – Raul Castro Rivero
            Mar 8 at 1:34











          • is the error still appear after you fix your typo and change componentWillMount ?

            – Jatmiko Herjati
            Mar 8 at 2:07











          • Exactly, the error lasts!

            – Raul Castro Rivero
            Mar 8 at 2:12
















          Thank you for your answer but I can not make it a stateless component because as its name indicates it is a form and I have to access that data and a method to save the form in the backend, I do not know if you understand me?

          – Raul Castro Rivero
          Mar 8 at 1:34





          Thank you for your answer but I can not make it a stateless component because as its name indicates it is a form and I have to access that data and a method to save the form in the backend, I do not know if you understand me?

          – Raul Castro Rivero
          Mar 8 at 1:34













          is the error still appear after you fix your typo and change componentWillMount ?

          – Jatmiko Herjati
          Mar 8 at 2:07





          is the error still appear after you fix your typo and change componentWillMount ?

          – Jatmiko Herjati
          Mar 8 at 2:07













          Exactly, the error lasts!

          – Raul Castro Rivero
          Mar 8 at 2:12





          Exactly, the error lasts!

          – Raul Castro Rivero
          Mar 8 at 2:12

















          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%2f55054643%2freact-undefined-setstate-from-props%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

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived