反应路由器提示在消息中传递自定义对象

时间:2018-09-26 16:22:03

标签: javascript reactjs react-router

我有以下内容:

export default (message, callback) => {
    const modal = document.createElement('div')
    document.body.appendChild(modal)

    const withCleanup = (answer) => {
        ReactDOM.unmountComponentAtNode(modal)
        document.body.removeChild(modal)
        callback(answer)
    };

    ReactDOM.render(
        <Modal>
            <header>Unsaved changes</header>
            <p>
                {message.message}
            </p>
            <Alert className="isError" />
            <div className="modal__buttons-wrapper">
                <Button onClick={() => withCleanup(true)}>Leave with unsaved changes</Button>
                <Button onClick={() => withCleanup(false)}>Cancel</Button>
            </div>
        </Modal>,
        modal
    )
};

<Prompt message={'alex'} when />

有没有办法像这样传递对象进行翻译?

我尝试过:

const message = {
    title: 'title',
    message: 'message'
}

<Prompt message={message} when />

但它坏了。

0 个答案:

没有答案