我有一个在footer
中创建的App.js
,现在有另一个名为KokPlayer.js
的组件,我想将按钮从KokPlayer.js
添加到{{1} }在footer
中。
我该怎么做?
App.js
App.js
KokPlayer.js
render() {
const { expanded } = this.state;
return (
<React.Fragment>
<nav
className="footer navbar navbar-light bg-success mb-auto"
ref="footerRef"
/>
</React.Fragment>
);
}
答案 0 :(得分:1)
据我所知,您可以在KokPlayer组件中传递一个道具,然后隐藏不想在App.js中显示的元素
在 App.js
中import KokPlayer from './KokPlayer' // KokPlayer location
....
render() {
const { expanded } = this.state;
return (
<React.Fragment>
<nav
className="footer navbar navbar-light bg-success mb-auto"
ref="footerRef"
/>
<KokPlayer showButtonsOnly={true} /> // the buttons here
</React.Fragment>
);
}
KokPlayer.js
render() {
// Add this block to footer
return (
<div>
{!this.props.showButtonsOnly && <div> // it wouldn't be shown in App.js
Screen Here
</div>}
<div style={{ display: "block", margin: "0 auto", verticalAlign: "middle" }}
>
<Button onClick={this.play} className="mr-3">
play()
</Button>
<Button onClick={this.pause} className="mr-3">
pause()
</Button>
<Button onClick={this.toggleFullScreen} className="mr-3">
FullScreen()
</Button>
</div>
</div>
);
}