You can pass it as props. I'll take a simple example for passing objects from a child to a parent component
Scenario
, , , , , .. / , ( ), , .
( )
import * as React from 'react';
import { IconButton, Button } from 'react-toolbox/lib/button';
interface IDeleteProps {
onDeleteClick: (e:boolean) => void;
}
class Delete extends React.Component<IDeleteProps, {}> {
constructor(props) {
super(props);
}
public onClickTrigger = () => {
this.props.onDeleteClick(true);
}
public render() {
return (
<Button icon='inbox' label='Delete' onClick={this.onClickTrigger} flat primary />
);
}
}
export default Delete;
, , , , (Item Component) , onDeleteClick prop . ()
import * as React from 'react';
import './styes.scss';
import Edit from '../item/operation/Edit';
import Delete from '../item/operation/Delete';
import View from '../item/operation/View';
const ReactGauge = require('react-gauge').default;
interface IItemProps {
item: any;
onDeleteChangeItem: (id: number) => void;
}
class Item extends React.Component<IItemProps, {}> {
constructor(props) {
super(props);
}
public deleteClickedEvent = (e: boolean) => {
if (e === true) {
this.props.onDeleteChangeItem(this.props.item.id);
}
}
public render() {
const dummyText = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\ standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.';
const itemStyle = {
backgroundImage: `url('${this.props.item.url}')`
};
return (
<div style={itemStyle} className='AudienceGridItem'>
<span className='name'>{this.props.item.id}</span>
<span className='name'>{this.props.item.name}</span>
<span className='name'>{this.props.item.customerCount}</span>
<span className='name'>{this.props.item.lastEdited}</span>
<span className='name'>{this.props.item.lastRerun}</span>
<ReactGauge
value={this.props.item.percentage}
width={140} height={70}
/>
<Edit />
<Delete onDeleteClick={this.deleteClickedEvent} />
<View />
</div>
);
}
}
export default Item;
Item "" , onDeleteClick deleteClickedEvent, . , , , , - , , ,