我的第一个 React/Redux 项目有一个问题,解决它可能并不难,但我很困惑。我想我已经做了工作所需的一切,但似乎没有。
所以,我有 HOC 组件PopupWindow.jsx
const PopupWindow = (WrappedComponent) => {
return function (props) {
const [show, setShow] = useState(false);
const handleClose = (value) => {
setShow(false);
if (value) {
props.createMovie(value);
}
}
const handleShow = () => setShow(true);
return (
<WrappedComponent show={show}
handleClose={handleClose}
handleShow={handleShow}
{...props}/>)
}
}
export default PopupWindow;
标头.jsx
const Header = ({handleShow, handleClose, show, createMovie}) => {
return (
<header className="img-blur-container header p-3">
<div className="container">
<div className="d-flex justify-content-between">
<Logo/>
<Button
className="header_add-movie text-uppercase f-size-18 px-4 py-2"
onClick={handleShow}
>+ Add movie</Button>
<AddMovie show={show} handleClose={handleClose}/>
</div>
<Search/>
</div>
</header>
)
}
function mapDispatchToProps(dispatch) {
return {
createMovie: (movie) => dispatch(createMovie(movie))
}
}
export default compose(connect(null, mapDispatchToProps),React.memo)(Header);
添加电影.jsx
const AddMovie = ({show, handleClose}) => {
const [movie] = movies;
delete movie.id;
拉风的咖菲猫
相关分类