From b60cc8a59faccbe5bb81d4578a82bea6c3195edb Mon Sep 17 00:00:00 2001
From: AQ-masatoshi-yamaguchi
<69567949+AQ-masatoshi-yamaguchi@users.noreply.github.com>
Date: Fri, 4 Feb 2022 15:46:06 +0900
Subject: [PATCH 1/6] initial commit
---
src/App.js | 6 ++++--
src/components/atoms/button/BaseButton.jsx | 13 +++++++++++++
src/components/atoms/button/PrimaryButton.jsx | 11 +++++++++++
src/components/atoms/button/SecondaryButton.jsx | 11 +++++++++++
4 files changed, 39 insertions(+), 2 deletions(-)
create mode 100644 src/components/atoms/button/BaseButton.jsx
create mode 100644 src/components/atoms/button/PrimaryButton.jsx
create mode 100644 src/components/atoms/button/SecondaryButton.jsx
diff --git a/src/App.js b/src/App.js
index dbc5c59..588bfdd 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,10 +1,12 @@
+import { PrimaryButton } from "./components/atoms/button/PrimaryButton";
+import { SecondaryButton } from "./components/atoms/button/SecondaryButton";
import "./styles.css";
export default function App() {
return (
-
Hello CodeSandbox
-
Start editing to see some magic happen!
+
テスト
+
検索
);
}
diff --git a/src/components/atoms/button/BaseButton.jsx b/src/components/atoms/button/BaseButton.jsx
new file mode 100644
index 0000000..85defb9
--- /dev/null
+++ b/src/components/atoms/button/BaseButton.jsx
@@ -0,0 +1,13 @@
+import styled from "styled-components";
+
+export const BaseButton = styled.button`
+ color: #fff;
+ padding: 6px 24px;
+ border: none;
+ border-radius: 9999px;
+ outline: none;
+ &:hover {
+ cursor: pointer;
+ opacity: 0.8;
+ }
+`;
diff --git a/src/components/atoms/button/PrimaryButton.jsx b/src/components/atoms/button/PrimaryButton.jsx
new file mode 100644
index 0000000..aa1c214
--- /dev/null
+++ b/src/components/atoms/button/PrimaryButton.jsx
@@ -0,0 +1,11 @@
+import styled from "styled-components";
+import { BaseButton } from "./BaseButton";
+
+export const PrimaryButton = (props) => {
+ const { children } = props;
+ return {children};
+};
+
+const SButton = styled(BaseButton)`
+ background-color: #40514e;
+`;
diff --git a/src/components/atoms/button/SecondaryButton.jsx b/src/components/atoms/button/SecondaryButton.jsx
new file mode 100644
index 0000000..6a6d4ec
--- /dev/null
+++ b/src/components/atoms/button/SecondaryButton.jsx
@@ -0,0 +1,11 @@
+import styled from "styled-components";
+import { BaseButton } from "./BaseButton";
+
+export const SecondaryButton = (props) => {
+ const { children } = props;
+ return {children};
+};
+
+const SButton = styled(BaseButton)`
+ background-color: #11999e;
+`;
From eb5cc7b7bed5a7e97d1d9b49ca12a401cbd27215 Mon Sep 17 00:00:00 2001
From: AQ-masatoshi-yamaguchi
<69567949+AQ-masatoshi-yamaguchi@users.noreply.github.com>
Date: Fri, 4 Feb 2022 16:37:30 +0900
Subject: [PATCH 2/6] Molecules
---
src/App.js | 3 +++
src/components/atoms/input/Input.jsx | 13 +++++++++++++
src/components/molecules/SearchInput.jsx | 24 ++++++++++++++++++++++++
3 files changed, 40 insertions(+)
create mode 100644 src/components/atoms/input/Input.jsx
create mode 100644 src/components/molecules/SearchInput.jsx
diff --git a/src/App.js b/src/App.js
index 588bfdd..396dedd 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,5 +1,6 @@
import { PrimaryButton } from "./components/atoms/button/PrimaryButton";
import { SecondaryButton } from "./components/atoms/button/SecondaryButton";
+import { SearchInput } from "./components/molecules/SearchInput";
import "./styles.css";
export default function App() {
@@ -7,6 +8,8 @@ export default function App() {
);
}
diff --git a/src/components/atoms/input/Input.jsx b/src/components/atoms/input/Input.jsx
new file mode 100644
index 0000000..95575ea
--- /dev/null
+++ b/src/components/atoms/input/Input.jsx
@@ -0,0 +1,13 @@
+import styled from "styled-components";
+
+export const Input = (props) => {
+ const { placeholder = "" } = props;
+ return ;
+};
+
+const SInput = styled.input`
+ padding: 8px 16px;
+ border: solid #ddd 1px;
+ border-radius: 9999px;
+ outline: none;
+`;
diff --git a/src/components/molecules/SearchInput.jsx b/src/components/molecules/SearchInput.jsx
new file mode 100644
index 0000000..047bdb9
--- /dev/null
+++ b/src/components/molecules/SearchInput.jsx
@@ -0,0 +1,24 @@
+import styled from "styled-components";
+
+import { PrimaryButton } from "../atoms/button/PrimaryButton";
+import { Input } from "../atoms/input/Input";
+
+export const SearchInput = () => {
+ return (
+
+
+
+ 検索
+
+
+ );
+};
+
+const SContainer = styled.div`
+ display: flex;
+ align-items: center;
+`;
+
+const SButtonWrapper = styled.div`
+ padding-left: 8px;
+`;
From b956a52d2598d45a4ff5fff84db1317d6207adfa Mon Sep 17 00:00:00 2001
From: AQ-masatoshi-yamaguchi
<69567949+AQ-masatoshi-yamaguchi@users.noreply.github.com>
Date: Sat, 5 Feb 2022 10:49:49 +0900
Subject: [PATCH 3/6] organism
---
src/App.js | 13 +++++++
src/components/atoms/card/Card.jsx | 13 +++++++
.../molecules/user/UserIconWithName.jsx | 26 ++++++++++++++
src/components/organisms/user/UserCard.jsx | 35 +++++++++++++++++++
src/styles.css | 7 ++--
5 files changed, 90 insertions(+), 4 deletions(-)
create mode 100644 src/components/atoms/card/Card.jsx
create mode 100644 src/components/molecules/user/UserIconWithName.jsx
create mode 100644 src/components/organisms/user/UserCard.jsx
diff --git a/src/App.js b/src/App.js
index 396dedd..95944ef 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,8 +1,20 @@
import { PrimaryButton } from "./components/atoms/button/PrimaryButton";
import { SecondaryButton } from "./components/atoms/button/SecondaryButton";
import { SearchInput } from "./components/molecules/SearchInput";
+import { UserCard } from "./components/organisms/user/UserCard";
import "./styles.css";
+const user = {
+ name: "まさお",
+ image: "https://source.unsplash.com/OzAeZPNsLXk",
+ email: "test@example.com",
+ phone: "020-0000-1111",
+ company: {
+ name: "テスト会社"
+ },
+ website: "https://google.com"
+};
+
export default function App() {
return (
@@ -10,6 +22,7 @@ export default function App() {
検索
+
);
}
diff --git a/src/components/atoms/card/Card.jsx b/src/components/atoms/card/Card.jsx
new file mode 100644
index 0000000..f91b47e
--- /dev/null
+++ b/src/components/atoms/card/Card.jsx
@@ -0,0 +1,13 @@
+import styled from "styled-components";
+
+export const Card = (props) => {
+ const { children } = props;
+ return {children};
+};
+
+const SCard = styled.div`
+ background-color: #fff;
+ box-shadow: #ddd 0px 0px 4px 2px;
+ border-radius: 8px;
+ padding: 16px;
+`;
diff --git a/src/components/molecules/user/UserIconWithName.jsx b/src/components/molecules/user/UserIconWithName.jsx
new file mode 100644
index 0000000..34986c2
--- /dev/null
+++ b/src/components/molecules/user/UserIconWithName.jsx
@@ -0,0 +1,26 @@
+import styled from "styled-components";
+
+export const UserIconWithName = (props) => {
+ const { image, name } = props;
+ return (
+
+
+ {name}
+
+ );
+};
+
+const SContainer = styled.div`
+ text-align: center;
+`;
+
+const SImage = styled.img`
+ border-radius: 50%;
+`;
+
+const SName = styled.p`
+ font-size: 18px;
+ font-weight: bold;
+ margin: 0;
+ color: #40514e;
+`;
diff --git a/src/components/organisms/user/UserCard.jsx b/src/components/organisms/user/UserCard.jsx
new file mode 100644
index 0000000..5c533d1
--- /dev/null
+++ b/src/components/organisms/user/UserCard.jsx
@@ -0,0 +1,35 @@
+import styled from "styled-components";
+import { Card } from "../../atoms/card/Card";
+import { UserIconWithName } from "../../molecules/user/UserIconWithName";
+
+export const UserCard = (props) => {
+ const { user } = props;
+ return (
+
+
+
+ メール
+ {user.email}
+ TEL
+ {user.phone}
+ 会社名
+ {user.company.name}
+ WEB
+ {user.website}
+
+
+ );
+};
+
+const SDL = styled.dl`
+ text-align: left;
+ margin-bottom: 0px;
+ dt {
+ float: left;
+ }
+ dd {
+ padding-left: 32px;
+ padding-bottom: 8px;
+ overflow-wrap: break-word;
+ }
+`;
diff --git a/src/styles.css b/src/styles.css
index 59b0604..275c868 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -1,4 +1,3 @@
-.App {
- font-family: sans-serif;
- text-align: center;
-}
+body {
+ background-color: #f0f8ff;
+}
\ No newline at end of file
From 60fdaec7118d8708345f01e0f0960b770be15c15 Mon Sep 17 00:00:00 2001
From: AQ-masatoshi-yamaguchi
<69567949+AQ-masatoshi-yamaguchi@users.noreply.github.com>
Date: Sat, 5 Feb 2022 11:31:22 +0900
Subject: [PATCH 4/6] templetes
---
src/App.js | 19 ++++++++++++-------
src/components/atoms/layout/Footer.jsx | 16 ++++++++++++++++
src/components/atoms/layout/Header.jsx | 22 ++++++++++++++++++++++
src/components/templates/DefaultLayout.jsx | 13 +++++++++++++
src/components/templates/HeaderOnly.jsx | 11 +++++++++++
src/styles.css | 6 ++++--
6 files changed, 78 insertions(+), 9 deletions(-)
create mode 100644 src/components/atoms/layout/Footer.jsx
create mode 100644 src/components/atoms/layout/Header.jsx
create mode 100644 src/components/templates/DefaultLayout.jsx
create mode 100644 src/components/templates/HeaderOnly.jsx
diff --git a/src/App.js b/src/App.js
index 95944ef..1838776 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,7 +1,10 @@
+import { BrowserRouter } from "react-router-dom";
import { PrimaryButton } from "./components/atoms/button/PrimaryButton";
import { SecondaryButton } from "./components/atoms/button/SecondaryButton";
import { SearchInput } from "./components/molecules/SearchInput";
import { UserCard } from "./components/organisms/user/UserCard";
+import { DefaultLayout } from "./components/templates/DefaultLayout";
+
import "./styles.css";
const user = {
@@ -17,12 +20,14 @@ const user = {
export default function App() {
return (
-
+
+
+ テスト
+ 検索
+
+
+
+
+
);
}
diff --git a/src/components/atoms/layout/Footer.jsx b/src/components/atoms/layout/Footer.jsx
new file mode 100644
index 0000000..4effafa
--- /dev/null
+++ b/src/components/atoms/layout/Footer.jsx
@@ -0,0 +1,16 @@
+import { Link } from "react-router-dom";
+import styled from "styled-components";
+
+export const Footer = () => {
+ return © 2021 test;
+};
+
+const SFooter = styled.footer`
+ background-color: #11999e;
+ color: #fff;
+ text-align: center;
+ padding: 8px 0;
+ position: fixed;
+ bottom: 0;
+ width: 100%;
+`;
diff --git a/src/components/atoms/layout/Header.jsx b/src/components/atoms/layout/Header.jsx
new file mode 100644
index 0000000..cea1848
--- /dev/null
+++ b/src/components/atoms/layout/Header.jsx
@@ -0,0 +1,22 @@
+import { Link } from "react-router-dom";
+import styled from "styled-components";
+
+export const Header = () => {
+ return (
+
+ HOME
+ USERS
+
+ );
+};
+
+const SHeader = styled.header`
+ background-color: #11999e;
+ color: fff;
+ text-align: center;
+ padding: 8px 0;
+`;
+
+const SLink = styled(Link)`
+ margin: 0 8px;
+`;
diff --git a/src/components/templates/DefaultLayout.jsx b/src/components/templates/DefaultLayout.jsx
new file mode 100644
index 0000000..5197113
--- /dev/null
+++ b/src/components/templates/DefaultLayout.jsx
@@ -0,0 +1,13 @@
+import { Footer } from "../atoms/layout/Footer";
+import { Header } from "../atoms/layout/Header";
+
+export const DefaultLayout = (props) => {
+ const { children } = props;
+ return (
+ <>
+
+ {children}
+
+ >
+ );
+};
diff --git a/src/components/templates/HeaderOnly.jsx b/src/components/templates/HeaderOnly.jsx
new file mode 100644
index 0000000..5db10cb
--- /dev/null
+++ b/src/components/templates/HeaderOnly.jsx
@@ -0,0 +1,11 @@
+import { Header } from "../atoms/layout/Header";
+
+export const HeaderOnly = (props) => {
+ const { children } = props;
+ return (
+ <>
+
+ {children}
+ >
+ );
+};
diff --git a/src/styles.css b/src/styles.css
index 275c868..e9bb231 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -1,3 +1,5 @@
body {
- background-color: #f0f8ff;
-}
\ No newline at end of file
+ background-color: #e4f9f5;
+ margin: 0;
+ min-height: 100vh;
+}
From 5803e58841eeb695361d5f8348d5fd71a83ed00f Mon Sep 17 00:00:00 2001
From: AQ-masatoshi-yamaguchi
<69567949+AQ-masatoshi-yamaguchi@users.noreply.github.com>
Date: Sat, 5 Feb 2022 12:27:12 +0900
Subject: [PATCH 5/6] Page
---
src/App.js | 30 ++--------------------
src/components/pages/Top.jsx | 13 ++++++++++
src/components/pages/Users.jsx | 46 ++++++++++++++++++++++++++++++++++
src/router/Router.jsx | 24 ++++++++++++++++++
4 files changed, 85 insertions(+), 28 deletions(-)
create mode 100644 src/components/pages/Top.jsx
create mode 100644 src/components/pages/Users.jsx
create mode 100644 src/router/Router.jsx
diff --git a/src/App.js b/src/App.js
index 1838776..1dec194 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,33 +1,7 @@
-import { BrowserRouter } from "react-router-dom";
-import { PrimaryButton } from "./components/atoms/button/PrimaryButton";
-import { SecondaryButton } from "./components/atoms/button/SecondaryButton";
-import { SearchInput } from "./components/molecules/SearchInput";
-import { UserCard } from "./components/organisms/user/UserCard";
-import { DefaultLayout } from "./components/templates/DefaultLayout";
+import { Router } from "./router/Router";
import "./styles.css";
-const user = {
- name: "まさお",
- image: "https://source.unsplash.com/OzAeZPNsLXk",
- email: "test@example.com",
- phone: "020-0000-1111",
- company: {
- name: "テスト会社"
- },
- website: "https://google.com"
-};
-
export default function App() {
- return (
-
-
- テスト
- 検索
-
-
-
-
-
- );
+ return ;
}
diff --git a/src/components/pages/Top.jsx b/src/components/pages/Top.jsx
new file mode 100644
index 0000000..c12081c
--- /dev/null
+++ b/src/components/pages/Top.jsx
@@ -0,0 +1,13 @@
+import styled from "styled-components";
+
+export const Top = () => {
+ return (
+
+ Topページ
+
+ );
+};
+
+const SContainer = styled.div`
+ text-align: center;
+`;
diff --git a/src/components/pages/Users.jsx b/src/components/pages/Users.jsx
new file mode 100644
index 0000000..21dabbc
--- /dev/null
+++ b/src/components/pages/Users.jsx
@@ -0,0 +1,46 @@
+import styled from "styled-components";
+import { SearchInput } from "../molecules/SearchInput";
+import { UserCard } from "../organisms/user/UserCard";
+
+export const Users = () => {
+ const users = [...Array(10).keys()].map((val) => {
+ return {
+ id: val,
+ name: `まさお${val}`,
+ image: "https://source.unsplash.com/OzAeZPNsLXk",
+ email: "test@example.com",
+ phone: "020-0000-1111",
+ company: {
+ name: "テスト会社"
+ },
+ website: "https://google.com"
+ };
+ });
+
+ return (
+
+ ユーザー一覧
+
+
+ {users.map((user) => (
+
+ ))}
+
+
+ );
+};
+
+const SContainer = styled.div`
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ padding: 24px;
+`;
+
+const SUserArea = styled.div`
+ padding-top: 40px;
+ width: 100%;
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
+ grid-gap: 20px;
+`;
diff --git a/src/router/Router.jsx b/src/router/Router.jsx
new file mode 100644
index 0000000..b820bae
--- /dev/null
+++ b/src/router/Router.jsx
@@ -0,0 +1,24 @@
+import { BrowserRouter, Switch, Route } from "react-router-dom";
+import { Top } from "../components/pages/Top";
+import { Users } from "../components/pages/Users";
+import { DefaultLayout } from "../components/templates/DefaultLayout";
+import { HeaderOnly } from "../components/templates/HeaderOnly";
+
+export const Router = () => {
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
From 00bf2538524b94ba867f39197f4171cd4b6ba09e Mon Sep 17 00:00:00 2001
From: AQ-masatoshi-yamaguchi
<69567949+AQ-masatoshi-yamaguchi@users.noreply.github.com>
Date: Tue, 8 Feb 2022 15:20:31 +0900
Subject: [PATCH 6/6] =?UTF-8?q?state=E7=AE=A1=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/App.js | 7 +++-
.../atoms/button/SecondaryButton.jsx | 4 +-
src/components/molecules/SearchInput.jsx | 6 ++-
.../molecules/user/UserIconWithName.jsx | 18 ++++++++-
src/components/organisms/user/UserCard.jsx | 7 +++-
src/components/pages/Top.jsx | 21 +++++++++++
src/components/pages/Users.jsx | 37 ++++++++++++-------
src/providers/UserProvider.jsx | 14 +++++++
8 files changed, 91 insertions(+), 23 deletions(-)
create mode 100644 src/providers/UserProvider.jsx
diff --git a/src/App.js b/src/App.js
index 1dec194..8d67433 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,7 +1,12 @@
import { Router } from "./router/Router";
+import { UserProvider } from "./providers/UserProvider";
import "./styles.css";
export default function App() {
- return ;
+ return (
+
+
+
+ );
}
diff --git a/src/components/atoms/button/SecondaryButton.jsx b/src/components/atoms/button/SecondaryButton.jsx
index 6a6d4ec..9233cf1 100644
--- a/src/components/atoms/button/SecondaryButton.jsx
+++ b/src/components/atoms/button/SecondaryButton.jsx
@@ -2,8 +2,8 @@ import styled from "styled-components";
import { BaseButton } from "./BaseButton";
export const SecondaryButton = (props) => {
- const { children } = props;
- return {children};
+ const { children, onClick } = props;
+ return {children};
};
const SButton = styled(BaseButton)`
diff --git a/src/components/molecules/SearchInput.jsx b/src/components/molecules/SearchInput.jsx
index 047bdb9..8af5a66 100644
--- a/src/components/molecules/SearchInput.jsx
+++ b/src/components/molecules/SearchInput.jsx
@@ -1,9 +1,11 @@
import styled from "styled-components";
+import { memo } from "react";
import { PrimaryButton } from "../atoms/button/PrimaryButton";
import { Input } from "../atoms/input/Input";
-export const SearchInput = () => {
+export const SearchInput = memo(() => {
+ console.log("SearchInput");
return (
@@ -12,7 +14,7 @@ export const SearchInput = () => {
);
-};
+});
const SContainer = styled.div`
display: flex;
diff --git a/src/components/molecules/user/UserIconWithName.jsx b/src/components/molecules/user/UserIconWithName.jsx
index 34986c2..0026395 100644
--- a/src/components/molecules/user/UserIconWithName.jsx
+++ b/src/components/molecules/user/UserIconWithName.jsx
@@ -1,14 +1,22 @@
+import { useContext, memo } from "react";
import styled from "styled-components";
+import { UserContext } from "../../../providers/UserProvider";
+
+export const UserIconWithName = memo((props) => {
+ console.log("UserIconWithName");
-export const UserIconWithName = (props) => {
const { image, name } = props;
+ const { userInfo } = useContext(UserContext);
+ const isAdmin = userInfo ? userInfo.isAdmin : false;
+
return (
{name}
+ {isAdmin && 編集}
);
-};
+});
const SContainer = styled.div`
text-align: center;
@@ -24,3 +32,9 @@ const SName = styled.p`
margin: 0;
color: #40514e;
`;
+
+const SEdit = styled.span`
+ text-decoration: underline;
+ color: #aaa;
+ cursor: pointer;
+`;
diff --git a/src/components/organisms/user/UserCard.jsx b/src/components/organisms/user/UserCard.jsx
index 5c533d1..d36b05e 100644
--- a/src/components/organisms/user/UserCard.jsx
+++ b/src/components/organisms/user/UserCard.jsx
@@ -1,8 +1,11 @@
import styled from "styled-components";
import { Card } from "../../atoms/card/Card";
import { UserIconWithName } from "../../molecules/user/UserIconWithName";
+import { memo } from "react";
+
+export const UserCard = memo((props) => {
+ console.log("UserCard");
-export const UserCard = (props) => {
const { user } = props;
return (
@@ -19,7 +22,7 @@ export const UserCard = (props) => {
);
-};
+});
const SDL = styled.dl`
text-align: left;
diff --git a/src/components/pages/Top.jsx b/src/components/pages/Top.jsx
index c12081c..0d8325d 100644
--- a/src/components/pages/Top.jsx
+++ b/src/components/pages/Top.jsx
@@ -1,9 +1,30 @@
import styled from "styled-components";
+import { SecondaryButton } from "../atoms/button/SecondaryButton";
+import { useHistory } from "react-router-dom";
+import { useContext } from "react";
+import { UserContext } from "../../providers/UserProvider";
export const Top = () => {
+ const history = useHistory();
+ const { setUserInfo } = useContext(UserContext);
+
+ const onClickAdmin = () => {
+ setUserInfo({ isAdmin: true });
+ history.push("/users");
+ };
+
+ const onClickGeneral = () => {
+ setUserInfo({ isAdmin: false });
+ history.push("/users");
+ };
+
return (
Topページ
+ 管理者ユーザー
+
+
+ 一般ユーザー
);
};
diff --git a/src/components/pages/Users.jsx b/src/components/pages/Users.jsx
index 21dabbc..518d4e1 100644
--- a/src/components/pages/Users.jsx
+++ b/src/components/pages/Users.jsx
@@ -1,26 +1,35 @@
+import { useContext } from "react";
import styled from "styled-components";
+import { UserContext } from "../../providers/UserProvider";
+import { SecondaryButton } from "../atoms/button/SecondaryButton";
+
import { SearchInput } from "../molecules/SearchInput";
import { UserCard } from "../organisms/user/UserCard";
+const users = [...Array(10).keys()].map((val) => {
+ return {
+ id: val,
+ name: `まさお${val}`,
+ image: "https://source.unsplash.com/OzAeZPNsLXk",
+ email: "test@example.com",
+ phone: "020-0000-1111",
+ company: {
+ name: "テスト会社"
+ },
+ website: "https://google.com"
+ };
+});
+
export const Users = () => {
- const users = [...Array(10).keys()].map((val) => {
- return {
- id: val,
- name: `まさお${val}`,
- image: "https://source.unsplash.com/OzAeZPNsLXk",
- email: "test@example.com",
- phone: "020-0000-1111",
- company: {
- name: "テスト会社"
- },
- website: "https://google.com"
- };
- });
+ const { userInfo, setUserInfo } = useContext(UserContext);
+ const onClickSwitch = () => setUserInfo({ isAdmin: !userInfo.isAdmin });
return (
ユーザー一覧
-
+
+
+ 切り替え
{users.map((user) => (
diff --git a/src/providers/UserProvider.jsx b/src/providers/UserProvider.jsx
new file mode 100644
index 0000000..7786472
--- /dev/null
+++ b/src/providers/UserProvider.jsx
@@ -0,0 +1,14 @@
+import { createContext, useState } from "react";
+
+export const UserContext = createContext({});
+
+export const UserProvider = (props) => {
+ const { children } = props;
+ const [userInfo, setUserInfo] = useState(null);
+
+ return (
+
+ {children}
+
+ );
+};