Skip to content

Commit

Permalink
learn: react context api
Browse files Browse the repository at this point in the history
  • Loading branch information
kherin committed Feb 13, 2024
1 parent 8578054 commit de0cde0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
24 changes: 6 additions & 18 deletions advanced_react/src/App.js
Original file line number Diff line number Diff line change
@@ -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 (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<h1>{theme}</h1>
<input type="checkbox" checked={theme === "light"} onChange={toggleTheme} />
</div>
);
}
};

export default App;
17 changes: 10 additions & 7 deletions advanced_react/src/index.js
Original file line number Diff line number Diff line change
@@ -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(
<React.StrictMode>
<App />
<ThemeProvider>
<App />
</ThemeProvider>
</React.StrictMode>
);

Expand Down

0 comments on commit de0cde0

Please sign in to comment.