例如,我想将状态传递给另一个组件。我知道我可以像这样传递它,但是我必须在将要返回组件的return方法中执行此操作。我不想返回我只想传递的该组件状态为component.Any方法为此??? 对不起,英语不好。
const ShowProjectCards = (props) => {
const [index,setIndex] = useState('')
let history = useHistory();
const onViewProjectProfileHandler = (i) => {
setIndex(i);
history.push('/ProjectProfile');
}
return (
<Aux>
<div>
{ props.projectFormData.map( (project , i) =>
<div key = {i}>
<Card style={{ width: '18rem' }} className = {classes.ShowCard}>
<Card.Header style = {{ width: '100%' }} >{project.projectQuality}</Card.Header>
<Card.Body>
<Card.Title>{project.projectName}</Card.Title>
<Card.Text>{project.textarea}</Card.Text>
<Button
onClick = { () => onViewProjectProfileHandler(i)}
variant="primary">
View Project
</Button>
</Card.Body>
</Card>
</div>
)}
</div>
</Aux>
)
}
const mapStateToProps = (state) => {
return {
projectFormData : state.reducer.projectFormData
}
}
export default connect(mapStateToProps,null)(ShowProjectCards);