Skip to content

Commit

Permalink
Added Jōtai (#345)
Browse files Browse the repository at this point in the history
* Created jotai folder
Installed react
Installed jotai
Uninstalled unnecessary packages
Removed unnecessary folders and files
Working on jotai

* Added Jotai example
Added Jotai to README.md file
Added jalalbmnf to .all-contributorsrc file

Co-authored-by: Jalal Manafi <[email protected]>
  • Loading branch information
jalalmanafi and Jalal Manafi authored Jan 9, 2023
1 parent b94d24b commit 0e89c11
Show file tree
Hide file tree
Showing 10 changed files with 15,099 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,16 @@
"doc",
"example"
]
},
{
"login":"jalalbmnf",
"name":"Jalal Manafi",
"avatar_url":"https://avatars.githubusercontent.com/u/53921355?v=4",
"profile":"https://github.com/jalalbmnf",
"contributions":[
"code",
"example"
]
}
]
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
| [Recoil](https://github.com/facebookexperimental/Recoil) | [<img src="./_art/csb.png" width="40px" />](https://codesandbox.io/s/github/GantMan/ReactStateMuseum/tree/master/React/recoil) [<img src="./_art/octo.png" width="36px" />](https://github.com/GantMan/ReactStateMuseum/tree/master/React/recoil) | Coming Soon - Contribute Here? |
| [Effector](https://github.com/effector/effector) | [<img src="./_art/csb.png" width="40px" />](https://codesandbox.io/s/github/GantMan/ReactStateMuseum/tree/master/Effector/effector) [<img src="./_art/octo.png" width="36px" />](https://github.com/GantMan/ReactStateMuseum/tree/master/Effector/effector) | Coming Soon - Contribute Here? |
| [zustand](https://zustand.surge.sh) | [<img src="./_art/csb.png" width="40px" />](https://codesandbox.io/s/github/GantMan/ReactStateMuseum/tree/master/React/zustand) [<img src="./_art/octo.png" width="36px" />](https://github.com/GantMan/ReactStateMuseum/tree/master/React/zustand) | Coming Soon - Contribute Here? |
| [Jōtai](https://jotai.org) | [<img src="./_art/csb.png" width="40px" />](https://codesandbox.io/s/github/GantMan/ReactStateMuseum/tree/master/React/jotai) [<img src="./_art/octo.png" width="36px" />](https://github.com/GantMan/ReactStateMuseum/tree/master/React/jotai) | Coming Soon - Contribute Here? |


### Examples to help portray the how, why, which, pros, and cons of various state management systems in the React ecosystem.
Expand Down
5 changes: 5 additions & 0 deletions React/jotai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
If you use yarn, run:
`yarn && yarn start`

If you use npm, run:
`npm i && npm run start`
14,923 changes: 14,923 additions & 0 deletions React/jotai/package-lock.json

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions React/jotai/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "react-jotai",
"version": "0.1.0",
"author": "jalalbmnf",
"description": "React State Museum - Example of Jōtai",
"dependencies": {
"jotai": "^1.12.1",
"packlist-components": "^1.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
42 changes: 42 additions & 0 deletions React/jotai/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React State Museum - Example of Jōtai</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
29 changes: 29 additions & 0 deletions React/jotai/src/Components/addItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { AddPackingItem } from "packlist-components";
import { useAtom, useSetAtom } from "jotai";

import { initialValue, items } from "../store";

const AddItem = () => {
const [item, setItem] = useAtom(initialValue);
const setItemList = useSetAtom(items);

const addItem = () => {
setItemList((prev) => [...prev, item]);
setItem("");
};

const clearlist = () => {
setItemList([]);
};

return (
<AddPackingItem
value={item}
addItem={addItem}
setNewItemText={(e) => setItem(e.target.value)}
clear={clearlist}
/>
);
};

export default AddItem;
12 changes: 12 additions & 0 deletions React/jotai/src/Components/listItems.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useAtom } from "jotai";
import { SimpleList } from "packlist-components";

import { items } from "../store";

const ListItem = () => {
const [list] = useAtom(items);

return <SimpleList value={list} />;
};

export default ListItem;
38 changes: 38 additions & 0 deletions React/jotai/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/************************************************
* This example is one of many examples
* -= The React State Museum =-
* View other state management options and read
* more in the blog post and the master repo:
*
* https://github.com/GantMan/ReactStateMuseum
************************************************/
import React from "react";
import ReactDOM from "react-dom/client";
import { Provider } from "jotai";

import ListItems from "./Components/listItems";
import AddItems from "./Components/addItem";

const styles = {
fontFamily: "sans-serif",
textAlign: "center",
};

const App = () => {
return (
<div style={styles}>
<h2>Welcome to Jōtai</h2>
<AddItems />
<ListItems />
</div>
);
};

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<Provider>
<App />
</Provider>
</React.StrictMode>
);
4 changes: 4 additions & 0 deletions React/jotai/src/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { atom } from "jotai";

export const items = atom(["nachos", "burritos", "hotdog"]);
export const initialValue = atom("");

0 comments on commit 0e89c11

Please sign in to comment.