-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from 14-team13/13-feature-state-management-recoil
13 feature state management recoil
- Loading branch information
Showing
9 changed files
with
80 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { atom, RecoilEnv } from "recoil"; | ||
RecoilEnv.RECOIL_DUPLICATE_ATOM_KEY_CHECKING_ENABLED = false; | ||
|
||
export const countState = atom({ | ||
key: "countState", | ||
default: 0 | ||
}); | ||
|
||
export const userState = atom({ | ||
key: 'user', | ||
default: { email: '[email protected]', username: 'aluminum' } | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from "react"; | ||
import { useRecoilState, useResetRecoilState, useRecoilValue } from "recoil"; | ||
import { userState } from "host/atoms"; | ||
import { countState } from "host/atoms"; | ||
|
||
export const Counter = () => { | ||
const [count, setCount] = useRecoilState(countState); | ||
const user = useRecoilValue(userState); | ||
const resetCount = useResetRecoilState(countState); | ||
|
||
const increase = () => { | ||
setCount(count + 1); | ||
}; | ||
|
||
const reset = () => { | ||
resetCount(); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div> | ||
<div>{user.email}</div> | ||
<div>{user.username}</div> | ||
</div> | ||
<h2>{count}</h2> | ||
<button onClick={() => increase()}>+</button> | ||
<button onClick={() => reset()}>reset</button> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters