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
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
add a comment |
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
add a comment |
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
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
javascript reactjs react-props react-state
edited Mar 8 at 12:20
ToneCrate
30539
30539
asked Mar 7 at 23:49
Raul Castro RiveroRaul Castro Rivero
85
85
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Two issues:
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.
- 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.
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 meTypeError: 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
|
show 2 more comments
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.
How does that explain the error though?
– Felix Kling
Mar 8 at 0:02
I've changed...props
withprops
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
add a comment |
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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Two issues:
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.
- 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.
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 meTypeError: 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
|
show 2 more comments
Two issues:
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.
- 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.
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 meTypeError: 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
|
show 2 more comments
Two issues:
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.
- 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.
Two issues:
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.
- 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.
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 meTypeError: 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
|
show 2 more comments
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 meTypeError: 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
|
show 2 more comments
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.
How does that explain the error though?
– Felix Kling
Mar 8 at 0:02
I've changed...props
withprops
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
add a comment |
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.
How does that explain the error though?
– Felix Kling
Mar 8 at 0:02
I've changed...props
withprops
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
add a comment |
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.
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.
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
withprops
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
add a comment |
How does that explain the error though?
– Felix Kling
Mar 8 at 0:02
I've changed...props
withprops
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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