Skip to content

Commit

Permalink
다크모드 리덕스 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
riroan committed Apr 7, 2024
1 parent f3ecacf commit 3c24748
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
10 changes: 10 additions & 0 deletions riroan/src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from 'react'
import { UseDispatch, useDispatch } from 'react-redux'
import A from './components/A'
import Assist from './components/Assist'
import Div from './components/Div'
Expand All @@ -12,11 +13,20 @@ import Refer from './components/Refer'
import Ul from './components/Ul'
import './App.css'
import Link from './components/Link'
import { darkmodeActions } from './app/darkmodeSlice';

export default function App() {
const [visible, setVisible] = useState(true)
const dispatch = useDispatch()
return (
<div className="DefaultContainer">
<button
onClick={() => {
dispatch(darkmodeActions.toggle());
}}
>
Dark Mode
</button>
<Div>
<H2>
김명기<Assist> riroan</Assist>
Expand Down
19 changes: 19 additions & 0 deletions riroan/src/app/darkmodeSlice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { createSlice } from '@reduxjs/toolkit'

const darkmodeSlice = createSlice({
name: 'darkmode',
initialState: {
darkmode: '',
},
reducers: {
toggle(state) {
if (state.darkmode === '') {
state.darkmode = 'darkmode'
} else {
state.darkmode = ''
}
},
},
})
export const darkmodeActions = darkmodeSlice.actions
export default darkmodeSlice
6 changes: 6 additions & 0 deletions riroan/src/app/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { configureStore } from '@reduxjs/toolkit'
import darkmodeSlice from './darkmodeSlice'

const store = configureStore({ reducer: { darkmode: darkmodeSlice.reducer } })

export default store
8 changes: 7 additions & 1 deletion riroan/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import ReactDOM from 'react-dom/client'
import App from './App'
import './reset.css'
import './default.css'
import { Provider } from 'react-redux'
import store from './app/store'

const root = ReactDOM.createRoot(document.getElementById('root'))
root.render(<App />)
root.render(
<Provider store={store}>
<App />
</Provider>
)

0 comments on commit 3c24748

Please sign in to comment.