Passing props in child component from state of parent componentPass props to parent component in React.jsHow to pass props to this.props.childrenGetting a child's default props to set the state in the parent in ReactJSComponent state in ReactJSreact pass props from child to parent undefinedPassing onClick function as props to child component and using it to change parent component stateUpdate the state from child to parent component in ReactPass state to another components function with propsReact, updating state in child component using props after async call in parent componentReact: How do I pass a returned function value to a parent component?

is it possible for a vehicle to be manufactured witout a catalitic converter

Fixing obscure 8080 emulator bug?

How can I get an unreasonable manager to approve time off?

Is White controlling this game?

Why can't I use =default for default ctors with a member initializer list

What's up with this leaf?

Why didn't Voldemort recognize that Dumbledore was affected by his curse?

Implement Own Vector Class in C++

How is John Wick 3 a 15 certificate?

Does Disney no longer produce hand-drawn cartoon films?

How do governments keep track of their issued currency?

1980s live-action movie where individually-coloured nations on clouds fight

Extreme flexible working hours: how to control people and activities?

What is the actual quality of machine translations?

CROSS APPLY produces outer join

Can Rydberg constant be in joules?

What makes Ada the language of choice for the ISS's safety-critical systems?

Mathematically, why does mass matrix / load vector lumping work?

Inward extrusion is not working

Group Integers by Originality

What can I, as a user, do about offensive reviews in App Store?

How to hide rifle during medieval town entrance inspection?

Winning Strategy for the Magician and his Apprentice

Rebus with 20 song titles



Passing props in child component from state of parent component


Pass props to parent component in React.jsHow to pass props to this.props.childrenGetting a child's default props to set the state in the parent in ReactJSComponent state in ReactJSreact pass props from child to parent undefinedPassing onClick function as props to child component and using it to change parent component stateUpdate the state from child to parent component in ReactPass state to another components function with propsReact, updating state in child component using props after async call in parent componentReact: How do I pass a returned function value to a parent component?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am unable to use the state from Parent Component to child component on Google Maps component. This may sound a very basic question, however I am trying to understand the difference between one of props working and other not.



So I have a google maps component (import GoogleMapReact from 'google-map-react')



static defaultProps = 
center: lat: 62.10281, lng: -84.14565 ,
zoom: 11
;

constructor(props)
console.log(props);
super(props);


render()

return (
<div className='google-map' style= height: '100%', width: '100%' >
<GoogleMapReact
bootstrapURLKeys= key: 'somekey'
center=this.props.center
defaultZoom= this.props.zoom >
<AnyReactComponent
lat= this.props.lat
lng= this.props.lng
text= 'Wheres Waldo?'
/>
</GoogleMapReact>
</div>
)



and then from parent component



<MapComponent lat=this.state.latitude lng=this.state.longitude
center=lat: this.state.latitude, lng: this.state.longitude


I have checked the value to lat, lng and center in constructor and I am getting them as expected still map doesn't work



However, If I hardcode the value in center leaving the lat and lng getting value from state, then it does work.



Now this works, Can someone please explain this concept and the difference and how to overcome it? Your help is appreciated.



<MapComponent lat=this.state.latitude lng=this.state.longitude
center=lat: 62.10281, lng: -84.14565









share|improve this question
























  • Put console.log(this.props); into the render function before the return block. Tell us what's in the console in both of your testcases.

    – xDreamCoding
    Mar 24 at 18:39












  • I am getting the values I expect center: lat: "62.10281", lng: "-84.14565" lat: "62.10281" lng: "-84.14565" zoom: 11

    – Raj
    Mar 24 at 19:26












  • So the values are exactly the same in both cases hardcoded and from parent.state? Is there any error thrown?

    – xDreamCoding
    Mar 24 at 19:33











  • No error in console. That is I find strange and assumed I don't know some core concept. Is Child component rendered before this value is mapped. Just a note that the values coming from parent component are coming from an API, so possible that when child component is rendered, the values were not present. However, console log clearly state the values being logged.

    – Raj
    Mar 25 at 6:46

















0















I am unable to use the state from Parent Component to child component on Google Maps component. This may sound a very basic question, however I am trying to understand the difference between one of props working and other not.



So I have a google maps component (import GoogleMapReact from 'google-map-react')



static defaultProps = 
center: lat: 62.10281, lng: -84.14565 ,
zoom: 11
;

constructor(props)
console.log(props);
super(props);


render()

return (
<div className='google-map' style= height: '100%', width: '100%' >
<GoogleMapReact
bootstrapURLKeys= key: 'somekey'
center=this.props.center
defaultZoom= this.props.zoom >
<AnyReactComponent
lat= this.props.lat
lng= this.props.lng
text= 'Wheres Waldo?'
/>
</GoogleMapReact>
</div>
)



and then from parent component



<MapComponent lat=this.state.latitude lng=this.state.longitude
center=lat: this.state.latitude, lng: this.state.longitude


I have checked the value to lat, lng and center in constructor and I am getting them as expected still map doesn't work



However, If I hardcode the value in center leaving the lat and lng getting value from state, then it does work.



Now this works, Can someone please explain this concept and the difference and how to overcome it? Your help is appreciated.



<MapComponent lat=this.state.latitude lng=this.state.longitude
center=lat: 62.10281, lng: -84.14565









share|improve this question
























  • Put console.log(this.props); into the render function before the return block. Tell us what's in the console in both of your testcases.

    – xDreamCoding
    Mar 24 at 18:39












  • I am getting the values I expect center: lat: "62.10281", lng: "-84.14565" lat: "62.10281" lng: "-84.14565" zoom: 11

    – Raj
    Mar 24 at 19:26












  • So the values are exactly the same in both cases hardcoded and from parent.state? Is there any error thrown?

    – xDreamCoding
    Mar 24 at 19:33











  • No error in console. That is I find strange and assumed I don't know some core concept. Is Child component rendered before this value is mapped. Just a note that the values coming from parent component are coming from an API, so possible that when child component is rendered, the values were not present. However, console log clearly state the values being logged.

    – Raj
    Mar 25 at 6:46













0












0








0








I am unable to use the state from Parent Component to child component on Google Maps component. This may sound a very basic question, however I am trying to understand the difference between one of props working and other not.



So I have a google maps component (import GoogleMapReact from 'google-map-react')



static defaultProps = 
center: lat: 62.10281, lng: -84.14565 ,
zoom: 11
;

constructor(props)
console.log(props);
super(props);


render()

return (
<div className='google-map' style= height: '100%', width: '100%' >
<GoogleMapReact
bootstrapURLKeys= key: 'somekey'
center=this.props.center
defaultZoom= this.props.zoom >
<AnyReactComponent
lat= this.props.lat
lng= this.props.lng
text= 'Wheres Waldo?'
/>
</GoogleMapReact>
</div>
)



and then from parent component



<MapComponent lat=this.state.latitude lng=this.state.longitude
center=lat: this.state.latitude, lng: this.state.longitude


I have checked the value to lat, lng and center in constructor and I am getting them as expected still map doesn't work



However, If I hardcode the value in center leaving the lat and lng getting value from state, then it does work.



Now this works, Can someone please explain this concept and the difference and how to overcome it? Your help is appreciated.



<MapComponent lat=this.state.latitude lng=this.state.longitude
center=lat: 62.10281, lng: -84.14565









share|improve this question
















I am unable to use the state from Parent Component to child component on Google Maps component. This may sound a very basic question, however I am trying to understand the difference between one of props working and other not.



So I have a google maps component (import GoogleMapReact from 'google-map-react')



static defaultProps = 
center: lat: 62.10281, lng: -84.14565 ,
zoom: 11
;

constructor(props)
console.log(props);
super(props);


render()

return (
<div className='google-map' style= height: '100%', width: '100%' >
<GoogleMapReact
bootstrapURLKeys= key: 'somekey'
center=this.props.center
defaultZoom= this.props.zoom >
<AnyReactComponent
lat= this.props.lat
lng= this.props.lng
text= 'Wheres Waldo?'
/>
</GoogleMapReact>
</div>
)



and then from parent component



<MapComponent lat=this.state.latitude lng=this.state.longitude
center=lat: this.state.latitude, lng: this.state.longitude


I have checked the value to lat, lng and center in constructor and I am getting them as expected still map doesn't work



However, If I hardcode the value in center leaving the lat and lng getting value from state, then it does work.



Now this works, Can someone please explain this concept and the difference and how to overcome it? Your help is appreciated.



<MapComponent lat=this.state.latitude lng=this.state.longitude
center=lat: 62.10281, lng: -84.14565






reactjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 19:25







Raj

















asked Mar 24 at 18:11









RajRaj

107210




107210












  • Put console.log(this.props); into the render function before the return block. Tell us what's in the console in both of your testcases.

    – xDreamCoding
    Mar 24 at 18:39












  • I am getting the values I expect center: lat: "62.10281", lng: "-84.14565" lat: "62.10281" lng: "-84.14565" zoom: 11

    – Raj
    Mar 24 at 19:26












  • So the values are exactly the same in both cases hardcoded and from parent.state? Is there any error thrown?

    – xDreamCoding
    Mar 24 at 19:33











  • No error in console. That is I find strange and assumed I don't know some core concept. Is Child component rendered before this value is mapped. Just a note that the values coming from parent component are coming from an API, so possible that when child component is rendered, the values were not present. However, console log clearly state the values being logged.

    – Raj
    Mar 25 at 6:46

















  • Put console.log(this.props); into the render function before the return block. Tell us what's in the console in both of your testcases.

    – xDreamCoding
    Mar 24 at 18:39












  • I am getting the values I expect center: lat: "62.10281", lng: "-84.14565" lat: "62.10281" lng: "-84.14565" zoom: 11

    – Raj
    Mar 24 at 19:26












  • So the values are exactly the same in both cases hardcoded and from parent.state? Is there any error thrown?

    – xDreamCoding
    Mar 24 at 19:33











  • No error in console. That is I find strange and assumed I don't know some core concept. Is Child component rendered before this value is mapped. Just a note that the values coming from parent component are coming from an API, so possible that when child component is rendered, the values were not present. However, console log clearly state the values being logged.

    – Raj
    Mar 25 at 6:46
















Put console.log(this.props); into the render function before the return block. Tell us what's in the console in both of your testcases.

– xDreamCoding
Mar 24 at 18:39






Put console.log(this.props); into the render function before the return block. Tell us what's in the console in both of your testcases.

– xDreamCoding
Mar 24 at 18:39














I am getting the values I expect center: lat: "62.10281", lng: "-84.14565" lat: "62.10281" lng: "-84.14565" zoom: 11

– Raj
Mar 24 at 19:26






I am getting the values I expect center: lat: "62.10281", lng: "-84.14565" lat: "62.10281" lng: "-84.14565" zoom: 11

– Raj
Mar 24 at 19:26














So the values are exactly the same in both cases hardcoded and from parent.state? Is there any error thrown?

– xDreamCoding
Mar 24 at 19:33





So the values are exactly the same in both cases hardcoded and from parent.state? Is there any error thrown?

– xDreamCoding
Mar 24 at 19:33













No error in console. That is I find strange and assumed I don't know some core concept. Is Child component rendered before this value is mapped. Just a note that the values coming from parent component are coming from an API, so possible that when child component is rendered, the values were not present. However, console log clearly state the values being logged.

– Raj
Mar 25 at 6:46





No error in console. That is I find strange and assumed I don't know some core concept. Is Child component rendered before this value is mapped. Just a note that the values coming from parent component are coming from an API, so possible that when child component is rendered, the values were not present. However, console log clearly state the values being logged.

– Raj
Mar 25 at 6:46












0






active

oldest

votes












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%2f55326924%2fpassing-props-in-child-component-from-state-of-parent-component%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















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%2f55326924%2fpassing-props-in-child-component-from-state-of-parent-component%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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript