react 简单的用函数调出ui显示

import test from '../components/test'

const info = () => {
  test.info('This is a normal message');
};

render(){
retrun  <button onClick={info}>click me</button>
}

test.js

import React, { Component } from "react";
import ReactDOM from "react-dom";
import { Dialog, DialogTitle } from "@material-ui/core";

const Alert = (props) => (
  <Dialog open={true} fullWidth>
    <DialogTitle>{props.msg}</DialogTitle>
  </Dialog>
);

class Test extends Component {
  static info(msg) {
    const div = document.createElement("div");
    document.body.append(div);
    ReactDOM.render(<Alert msg={msg}/>, div);
  }
}
export default Test;
posted @ 2018-10-30 22:57  Ajanuw  阅读(267)  评论(0编辑  收藏  举报