Skip to content

Commit

Permalink
Feature: Add jotai State Management (#1)
Browse files Browse the repository at this point in the history
# Story Title
[Use Jotai as the state management](https://app.clickup.com/t/86epj20qp)

## Changes made

- Install Jotai
- Add Jotai Provider to Organism.Wrapper; Remove Redux Provider
- Add Page to test Jotai atoms

## How does the solution address the problem

This PR will update the state management to use Jotai instead of Redux.
  • Loading branch information
edwardlayaodev committed Jun 12, 2024
1 parent 7a7c639 commit 35a4f05
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 6 deletions.
5 changes: 2 additions & 3 deletions app/_components/organisms/Wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import StyledComponentsRegistry from "../../_utilities/antd_registry";
import ConfigProvider from "antd/es/config-provider";
import { StyleProvider } from "@ant-design/cssinjs";
import { Provider as ReduxProvider } from "react-redux";
import { store } from "@/app/_data/store";
import { ReactNode } from "react";
import { Provider as JotaiProvider } from "jotai";

interface IWrapperProps {
children: ReactNode;
Expand All @@ -15,7 +14,7 @@ const Wrapper: React.FunctionComponent<IWrapperProps> = ({ children }) => {
<StyledComponentsRegistry>
<ConfigProvider>
<StyleProvider hashPriority="high">
<ReduxProvider store={store}>{children}</ReduxProvider>
<JotaiProvider>{children}</JotaiProvider>
</StyleProvider>
</ConfigProvider>
</StyledComponentsRegistry>
Expand Down
4 changes: 4 additions & 0 deletions app/_data/atoms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use client";
import { atom } from "jotai";

export const msgAtom = atom("hello world");
30 changes: 30 additions & 0 deletions app/jotai-example/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client";
import { useAtom } from "jotai";
import { msgAtom } from "../_data/atoms";
import { useState } from "react";

export default function JotaiExamplePage() {
const [msg, setMsg] = useAtom(msgAtom);
const [input, setInput] = useState("");

return (
<div>
<h1>{msg}</h1>
<form
onSubmit={(e) => {
e.preventDefault();
setMsg(input);
}}
>
<input
className="border"
onChange={(e) => {
setInput(e.target.value);
}}
type="text"
/>
<button type="submit">submit</button>
</form>
</div>
);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"formik": "^2.4.5",
"graphql": "^16.8.1",
"graphql-request": "^6.1.0",
"jotai": "^2.8.3",
"lodash": "^4.17.21",
"next": "^13.5.4",
"react": "^18.2.0",
Expand Down
36 changes: 33 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4134,6 +4134,11 @@ jiti@^1.19.1:
resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.21.0.tgz#7c97f8fe045724e136a397f7340475244156105d"
integrity sha512-gFqAIbuKyyso/3G2qhiO2OM6shY6EPP/R0+mkDbyspxKazh8BXDC5FiFsUjlczgdNz/vfra0da2y+aHrusLG/Q==

jotai@^2.8.3:
version "2.8.3"
resolved "https://registry.yarnpkg.com/jotai/-/jotai-2.8.3.tgz#21b50c89c9ee2d24e694158b925bade1f38641d7"
integrity sha512-pR4plVvdbzB6zyt7VLLHPMAkcRSKhRIvZKd+qkifQLa3CEziEo1uwZjePj4acTmQrboiISBlYSdCz3gWcr1Nkg==

js-sdsl@^4.1.4:
version "4.4.2"
resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.4.2.tgz#2e3c031b1f47d3aca8b775532e3ebb0818e7f847"
Expand Down Expand Up @@ -5648,7 +5653,16 @@ string-length@^4.0.1:
char-regex "^1.0.2"
strip-ansi "^6.0.0"

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -5708,7 +5722,14 @@ string.prototype.trimstart@^1.0.7:
define-properties "^1.2.0"
es-abstract "^1.22.1"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -6235,7 +6256,16 @@ which@^2.0.1:
dependencies:
isexe "^2.0.0"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand Down

0 comments on commit 35a4f05

Please sign in to comment.