1. 程式人生 > >react 簡單的用函數調出ui顯示

react 簡單的用函數調出ui顯示

dialog click orm one prop true message nor wid

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;

react 簡單的用函數調出ui顯示