score:0
You will have to firstly set the hierarchy of your components such as parent, sibling or child component. You can pass information from parent to child component through props.
Reverse flow occurs as a callback function. If you want to call a function from parent component, create a function inside it and pass function as props.
class ReportModal extends React.Component {
constructor(props) {
super(props);
this.state = {
modal: false,
imagesList: [],
code: []
};
this.toggle = this.toggle.bind(this);
}
toggle(modal) {
this.setState({
modal: modal
});
}
render() {
return(
<component2 mod={this.toggle}/>
)
}
The child component will call this function on the occurrence of event and provide child data.
class Component2 extends React.Component {
constructor(props) {
super(props);
this.handleClick=this.handleClick.bind(this);
}
handleClick(){
this.props.mod(true)
}
render(){
return (
<button onClick={this.handleClick}></button>
)}
}
Source: stackoverflow.com
Related Query
- how to pass just the function from one component to other component without passing the whole component or button click
- How to pass route parameters from one Component and display in the other
- How do you pass data from one view to the other via react-router-dom without using url parameters?
- How to pass a dynamic value from one component to the other in React
- React Native - How to pass the Image from the other Component without using React Redux
- How to call a component function on other component, but from the other component ? React
- How to pass function as props from one functional component to another?
- How to pass function from FUNCTIONAL to CLASS component and access it outside of render( without prop ), using context in react js?
- Need Reactjs help on how to properly pass this function from the parent to child button component
- How to pass the variable from one component to another
- How to pass props from html div to the function component in react?
- How to call Child function from Parent / Pass Props to a Parent component without using ref methods?
- How to pass info from a child component to a function in the parent component? (REACT NATIVE)
- how to call a function from child components to parent component(function is in parent) without including the full component
- how to pass the data from one component to another in react js
- How to pass data from one component to another via a function in ReactJS?
- How can I pass the state from one component to another and how can I modify the state?
- How to pass method from one component to another without using Arrow Function?
- How to pass data from a parent component or use axios here in the map function for react-google-maps library?
- How to pass data from child component to parent component without the child component rerendering in React?
- How to Pass a value from One Function to Another without Triggering Another Function?
- How can i pass and display data from one component to other component?
- React: How to pass the data from function located on the child component into parent component?
- How can I pass the value from my function to another component in another file
- how to pass props from one component to other in react router that don't have parent child relationship?
- How do I pass the properties from one component to another in React
- How to pass a state value from one component to another component at the same level
- How can i pass different props to more than one children component from the parent one in React?
- ReactJS - How to pass state data and functions from one functional component to other component?
- How can i pass props from a functional button component to another function component that displays the prop?
More Query from same tag
- Link: unknown props found: onClick
- React js : Change img on Div whith onMouseOver
- How do I take a mongodb json to flask to react?
- Execute a code after change in two states in react using hooks
- How do I get tailwinds active breakpoint in JavaScript?
- React Forms : How to make input data as list objects with same input name?
- Ant design Modal remove or change the black background
- Pass environment variable from package.json to React app
- React component does not call onClick handler
- Deploy React components to many personal projects
- How to pass an empty value to DatePicker and avoid input blocking?
- Pasting of text is being duplicated in textbox in React Component
- Change checked state of a material-ui switch onChange
- How do I load and link an svg file with webpack 2.2.1?
- React filtering a list
- How to handle network failure in React-Native, when network is off
- How to Test AgGridReact with Jest/Enzyme
- SPFx ListView control - "defaultSelection" does not work
- Why won't URL be placed in the state array?
- Can not change default locale of moment.js in react component
- React Router - Change state of other components
- Update one element of State React
- How do i get multiple parameters working with React Router
- Manipulate data output from get(this.props 'data')
- React add table cell flash animation on useState change
- page permission check with react router v6
- How to get imported functions to set state of functional component?
- How Do I make my Nav Menu option change color or background when I click on it using Javascript only?
- Fields are not editable using React Hook Form
- !important on makeStyle