import { Link } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import { logout } from '../../redux/modules/authSlice';
<Stbutton>
{isLogin ? (
<>
<Link to="/profile">
<button>λ§μ΄νμ΄μ§</button>
</Link>
<Link to="/Write">
<button>κ²μλ¬Ό μ¬λ¦¬κΈ°</button>
</Link>
<button
onClick={() => {
alert('μ λ§ λ‘κ·Έμμ νμκ² μ΅λκΉ?');
dispatch(logout());
}}
>
λ‘κ·Έμμ
</button>
</>
) : (
<>
<Link to="/register">
<button>νμκ°μ
</button>
</Link>
<Link to="/login">
<button>λ‘κ·ΈμΈ</button>
</Link>
</>
)}
</Stbutton>
// Common ν΄λ
// Header.jsx
import {
StHeader,
StLogo,
StBtnInputWrapper,
Stbutton,
SearchContainer,
SearchInput,
SearchImage
} from './styles';
// styles.js
import styled from 'styled-components';
export const StBtnInputWrapper = styled.div`
display: flex;
justify-content: center;
align-items: center;
margin-right: 20px;
gap: 50px;
`;
.
.
κΈ°μ‘΄μλ Login.jsxμ Register.jsxμμ μ μμ
μ ν΄μ£Όκ³ μμλ€. μ΄λ μ λ κΈ°μ ꡬν λΌμ μ»΄ν¬λνΈ λΆλ¦¬λ₯Ό μν΄ λ¦¬ν©ν λ§μ νκ³ μλ μμ€ μ€λ₯ λ°μ..!
μ΄μ λ°μ νλ μ€λ₯ λ©μμ§μ κ΅μ₯ν ν‘μ¬νλ€. μ΄μ λ κ²°κ΅μ ν΄κ²°μ νμ§ λͺ»ν΄μ μ½λλ₯Ό λ€μ μ§°μλλ° μ€λλ λ λκ°μ μ€λ₯γ γ μ΄ μνλ‘λ λ€λ₯Έ νμ΄μ§μμ λ‘μ§μ μ§λ κ³μ κ°μ λ¬Έμ κ° λ°μ ν κ±° κ°μμ νμλΆλ€κ» λμμ μμ²ν΄λ΄€λ€.
node_modules ν΄λλ μ§μ°κ³ μ¬μ€μΉνκ³ export, importμ κ²½λ‘ λ¬Έμ λ μλμ§ μ€νλ μλμ§ μΌμΌν λͺ¨λ μ½λλ₯Ό λ€ νμΈν΄λ΄€λλ° μ ν λ¬Έμ κ° μμλ€. νμμ΄ λ³΄μκΈΈ 곡ν΅μ μΌλ‘ modules/authSliceμ κ²½λ‘ λ¬Έμ λΌκ³ νμ ¨λ€. κ²½λ‘λ₯Ό μ μ½μ§ λͺ»νλ κ±° κ°μμ λͺ¨λ νμΌμ import κ²½λ‘λ₯Ό νλνλ μ λλ‘ λͺ μλ₯Ό ν΄μ€¬λ€.
// signin.jsx
import { login } from 'redux/modules/authSlice';
β
import { login } from '../../redux/modules/authSlice';
// configStore.js
import authSlice from 'redux/modules/authSlice';
β
import authSlice from '../modules/authSlice';
μ΄μ κ°μ΄ λ°κΏμ£Όλ ν΄κ²°μ΄ λλ€. μ κ²½λ‘λ₯Ό μ λλ‘ μ½μ§ λͺ»νλμ§λ λͺ¨λ₯΄κ² μ§λ§ μ΄μ λΉμ·ν μ€λ₯κ° λ°μνμ λμ ν΄κ²°λ²μ μκ² λμΌλ κ·Έκ±Έλ‘ λ€νμ΄λ€!