Creating custom function in React component

前端 未结 4 678
南旧
南旧 2021-01-30 19:58

I have a React component

export default class Archive extends React.Component { 
   ...
}

componentDidMount and onClick

4条回答
  •  佛祖请我去吃肉
    2021-01-30 20:36

    With React Functional way

    import React, { useEffect } from "react";
    import ReactDOM from "react-dom";
    import Button from "@material-ui/core/Button";
    
    const App = () => {
      const saySomething = (something) => {
        console.log(something);
      };
      useEffect(() => {
        saySomething("from useEffect");
      });
      const handleClick = (e) => {
        saySomething("element clicked");
      };
      return (
        
      );
    };
    
    ReactDOM.render(, document.querySelector("#app"));
    

    https://codesandbox.io/s/currying-meadow-gm9g0

提交回复
热议问题