createContext
-
React/createContext, useContext 사용하기Language/React 2022. 10. 12. 16:56
Class Component -> createContext const MyContext = React.createContext(); class MyComponent extends Component { const [user, setUser] = useState(null); render() { const propsMy = { ... isMobile: () => { return this.isMobile }, ... }; return ( ... ... ); } }; export default MyComponent; Class Component -> useContext class UserComponent extends Component { static contextType = MyContext; state = {..