From de0cde0e595bc30b3b3c07aa6f973d5a874ddca2 Mon Sep 17 00:00:00 2001 From: Kherin Date: Tue, 13 Feb 2024 21:23:02 +0400 Subject: [PATCH] learn: react context api --- advanced_react/src/App.js | 24 ++++++------------------ advanced_react/src/index.js | 17 ++++++++++------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/advanced_react/src/App.js b/advanced_react/src/App.js index 3784575..92dc85f 100644 --- a/advanced_react/src/App.js +++ b/advanced_react/src/App.js @@ -1,25 +1,13 @@ -import logo from './logo.svg'; -import './App.css'; +import { useTheme, ThemeProvider } from "./ThemeContext"; -function App() { +const App = () => { + const { theme, toggleTheme } = useTheme(); return (
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
+

{theme}

+
); -} +}; export default App; diff --git a/advanced_react/src/index.js b/advanced_react/src/index.js index d563c0f..b7f28b3 100644 --- a/advanced_react/src/index.js +++ b/advanced_react/src/index.js @@ -1,13 +1,16 @@ -import React from 'react'; -import ReactDOM from 'react-dom/client'; -import './index.css'; -import App from './App'; -import reportWebVitals from './reportWebVitals'; +import React from "react"; +import ReactDOM from "react-dom/client"; +import "./index.css"; +import App from "./App"; +import reportWebVitals from "./reportWebVitals"; +import { ThemeProvider } from "./ThemeContext"; -const root = ReactDOM.createRoot(document.getElementById('root')); +const root = ReactDOM.createRoot(document.getElementById("root")); root.render( - + + + );