Skip to content

Commit

Permalink
global hook has become better
Browse files Browse the repository at this point in the history
  • Loading branch information
anilsenay committed Aug 2, 2020
1 parent 2623ff8 commit 97bbff3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
7 changes: 3 additions & 4 deletions atoms/globalState.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { atom } from "recoil";
const loginUser = atom({
key: "login_user",
default: {
username: "anilsenay",
name: "Anıl Şenay",
image:
"https://instagram.fsaw1-3.fna.fbcdn.net/v/t51.2885-19/s150x150/88129994_218553312873090_187843388282765312_n.jpg?_nc_ht=instagram.fsaw1-3.fna.fbcdn.net&_nc_ohc=siFEGZag29UAX9Sytdg&oh=56e1226fa0938ff569eb491980eb95a7&oe=5F4278CA",
username: "",
name: "",
image: "",
},
});

Expand Down
20 changes: 8 additions & 12 deletions hooks/global_hook.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import React from "react";
import { useRecoilState } from "recoil";
import { loginUser } from "../atoms/globalState";

function useLoginUserData() {
const [loginUserData, setLoginUserData] = useRecoilState(loginUser);

const data = loginUserData;
import { useRecoilState } from "recoil";

return data;
}
function setLoginUser(x) {
const LoginUserHook = () => {
const [loginUserData, setLoginUserData] = useRecoilState(loginUser);

setLoginUserData(x);
}
const { data } = loginUserData;
const setLoginUser = (newData) => setLoginUserData({ data: newData });

return { data, setLoginUser };
};

export { useLoginUserData, setLoginUser };
export default LoginUserHook;

0 comments on commit 97bbff3

Please sign in to comment.