score:11
you need to explicitly pass the props from parent to child. changing the render
function of commentbox
will fix the problem:
var commentbox = react.createclass({
render: function() {
return (
<div classname="commentbox">
<h1>comments</h1>
<commentlist />
//the next line is where you can pass the url to the commentform
<commentform url={this.props.url}/>
</div>
);
}
});
working jsfiddle adapted from your example: http://jsfiddle.net/kb3gn/10352/
the docs say "for parent-child communication, simply pass props." see http://facebook.github.io/react/tips/communicate-between-components.html
as an alternative to explicitly passing props, react's undocumented context
feature is closer to what you're looking for:
https://www.tildedave.com/2014/11/15/introduction-to-contexts-in-react-js.html
and is on the roadmap for 1.0 https://facebook.github.io/react/blog/2014/03/28/the-road-to-1.0.html#context.
that said, passing props is the normal pattern.
Source: stackoverflow.com
Related Query
- React what's the right way to get a parent props from its children
- Accessing React component children props from the parent
- Is there a way to force a re-render of a child component from the parent component without using changing its props in React?
- Is there a right way to pass data into a React component from the HTML page?
- What is the most effective way to get children at index in React
- Passing props from react router to children on the server
- Directly modify parent props from the child in react
- How to pass input values from a child Form component to the state of its parent component for submission with react hooks?
- How can I get the right data from database with react
- What's the redux-react way to manipulate props in react children component
- React Hooks - What is the recommended way to initialize state variables with useState() from props
- React - what is the right way to sum the value of object by its type and then setState
- React children component is not re-rendered after props from parent changed
- What is the most efficient way to transfer few props from a component to its child in ReactJS?
- update react child component's state using props received from an async api call made in the parent component
- How to get the current route from react without props
- Is it possible to get the name of a nested, inner React Component by calling a function from one of its props?
- How to get the cumulated height from children elements within a parent component
- How to pass state from child to parent by right way in React
- How to get parent props from child composition component React
- Best way to recieve props from child to parent react component
- Rerendering React child component when the parent updates its props in a Next.js app
- While deleting an element from an object, its deleting from the parent in react js
- What is the correct way to pass an argument to parent component in React from onClick event handler
- Passing props to Children component from Parent state- React Router
- Is there a way to get the Parent components name/displayName from within a Child component?
- How to get props from parent in React Styled Components
- Props object what is the meaning of passing children to the component from React official documentation
- What causes the failure to pass props from parent to child in this React application?
- how to get the updated data from parent to child as props
More Query from same tag
- Why my methods for React function components don't work
- Trying to get Material ui dialog into contextualised modal
- Run function in child component after action in parent component
- How to text-indent all input labels within a div?
- Rendering a React.Component
- Map() function returning as undefined when attempting to return query
- Overflow not being applied
- send Data from react to django rest api
- subtotal not updating after qty change
- Ant design Table configuration
- Loading CSS using Webpack and React
- Apache structure and config for React app with self hosted headless CMS
- React - Warning: Each child in a list should have a unique "key" prop
- React component do not gets rendered when loading the data from state
- ssr with react and express and requiring stats.json explanation
- React infinite loop using componentDidUpdate
- How to get the object in StyleSheet.create?(React Native)
- React: addEventListener() returns error when called inside of useEffect hook
- What is the simplest way to share react components between projects?
- Push to an array at a specific path of a useReducer's state
- Nesting a TypeScript React component inside another
- How to add if else inside the Tabs in react bootstrap
- Html scripts in react with div id not working
- render html in state string
- how to add Spinner while render a component on react?
- How to append data to existing data object
- Next Js Router.push is not a function error
- React Typescript destructure providerValue
- Delay load on every page with reach-router
- what is the best way to create a state of array or state of array of objects