我如何在反应中重新加载当前页面?

时间:2019-04-18 11:04:29

标签: reactjs

在这里,我要使用ApiClient提取数据,然后进行确认删除当前项目的操作。我的问题是单击Yes后如何重新加载页面?

type Props = {
    resourceName: string,
    label: string,
    accessor: string,
    row: Object,
}

@withRouter
@connectAPI((apiClient: ApiClient, props: Props) => ({
    deleteObject: {
        send: (id: any) => apiClient.resources[props.resourceName].delete(id),
        success: () => {
          // TODO: ?
        },
    },
}))
class DeleteComponent extends React.Component<Props> {
    state = {
        open: false,
    };

    handleOpen = () => {
        this.setState({ open: true });
    };

    handleConfirm = (props: Props) => {
        const { accessor, row, deleteObject } = props;

        const id = row._original[accessor];

        deleteObject({
            id,
        });
    };

    render(): React.ReactNode {
        const { open } = this.state;
        let message = null;
        if (open) {
            message = (
                <MessageDialog
                    message="Are tou sure you want to delete ?"
                    actions={{
                        yes: {
                            label: 'Yes',
                            callback: this.handleConfirm,
                        },
                        no: {
                            label: 'No',
                            callback: (e: SyntheticMouseEvent<HTMLButtonElement>) => this.setState({ open: false }),
                        },
                    }}
                />
            );
        }

        return (
            <React.Fragment>
                <Button
                    position="right"
                    onClick={this.handleOpen}
                    hoverIndicator="light-1"
                />
                {message}
            </React.Fragment>
        );
    }
}

export default DeleteComponent;

0 个答案:

没有答案