写bookmark的时候,点击收藏,再点击移除。
toast里面需要用到title,title是从父组件detail里面传到CollectFav里面的。
在constuctor里面props取没有用,为空。在render里面是有值的。
要用componentsWillReceiveProps接收title值并且给整个子component setState,那么在其他函数里面就可以直接用这个从父组件接受过来的title值了。这里用save和remove来写,和arrowDown 和up同理。
constructor() {
super()
this.state = {
title: []
}
this.save = this.save.bind(this)
this.remove = this.remove.bind(this)
}
save(){
console.log(this.state.title)
toast("Saving " + this.state.title)
ReactDOM.render(<FaBookmark onClick={this.remove}/>,document.getElementById("bookmark_part"))
}
remove(){
console.log(this.state.title)
toast("Removing - " + this.state.title)
ReactDOM.render(<FaRegBookmark onClick={this.save}/>,document.getElementById("bookmark_part"))
}
componentWillReceiveProps = (nextProps,prevState) => {
this.setState({
title: nextProps.title
}
)
}
render() {
return (
<div>
<ToastContainer position="top-center" autoClose={3000} hideProgressBar newestOnTop={false} closeOnClick rtl={false} pauseOnVisibilityChange={false} draggable={false} pauseOnHover transition={Zoom}/>
<div id="bookmark_part">
<FaRegBookmark onClick={this.save}/>
</div>
<ReactTooltip id='BookMark' place='top'>
<span>Bookmark</span>
</ReactTooltip>
</div>
)
}