我正在为我的 React 应用程序使用 material-ui 的Dialog 组件。如何将我的组件设置为一个变量,以便我可以调用该onShow()
方法?
问问题
30164 次
2 回答
2
我建议阅读Dan Abramov关于如何在 React 中实现模式的回答。
为了使用 material-ui 对话框,您可以将他的示例中的DeletePostModal替换为以下内容:
import { deletePost, hideModal } from '../actions';
import React, {Component} from 'react';
import {connect} from "react-redux";
import {Button, Dialog, DialogActions, DialogTitle} from "material-ui";
import PropTypes from 'prop-types';
const DeletePostModal = ({ post, dispatch }) => (
<Dialog open={true}>
<DialogTitle>Delete post {post.name}?</DialogTitle>
<DialogActions>
<button onClick={() => {
dispatch(deletePost(post.id)).then(() => {
dispatch(hideModal());
});
}}>
Yes
</button>
<button onClick={() => dispatch(hideModal())}>
Nope
</button>
</DialogActions>
</Dialog>
)
export default connect(
(state, ownProps) => ({
post: state.postsById[ownProps.postId]
})
)(DeletePostModal)
于 2017-11-15T06:41:07.917 回答