This commit is contained in:
@@ -40,6 +40,7 @@ function App(props) {
|
||||
<ThemeProvider>
|
||||
<ExampleUseContext />
|
||||
<hr />
|
||||
|
||||
<ExampleUseContext />
|
||||
</ThemeProvider>
|
||||
<hr />
|
||||
|
||||
@@ -12,13 +12,13 @@ function reducer(state, action) {
|
||||
const { type, payload = 1 } = action;
|
||||
switch (type) {
|
||||
case 'INCREASE':
|
||||
return { counter: state.counter + 1 };
|
||||
return { ...state, counter: state.counter + 1 };
|
||||
case 'DECREASE':
|
||||
return { counter: state.counter - 1 };
|
||||
return { ...state, counter: state.counter - 1 };
|
||||
case 'DOUBLE':
|
||||
return { counter: state.counter * 2 };
|
||||
return { ...state, counter: state.counter * 2 };
|
||||
case 'INC_VALUE':
|
||||
return { counter: state.counter + payload };
|
||||
return { ...state, counter: state.counter + payload };
|
||||
|
||||
default:
|
||||
console.warn('Action Type not found');
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createContext } from 'react';
|
||||
|
||||
export const THEME_DEFAULT_VALUE = 'light';
|
||||
|
||||
const ThemeContext = createContext(THEME_DEFAULT_VALUE); // standard theme is light;
|
||||
// ThemeContext wird durch createContext() zu einem JSX-Element
|
||||
|
||||
|
||||
Reference in New Issue
Block a user