Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added react-contextual example for react #57

Merged
merged 3 commits into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions React/react-contextual/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Instalation

If you use yarn, run:
`yarn && yarn start`

If you use npm, run:
`npm i && npm run start`

# Development

Please read all you can about [React Contextual](https://github.com/drcmda/react-contextual). There are some things really cool but a bit confusing when using this library :D.
21 changes: 21 additions & 0 deletions React/react-contextual/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "react-contextual-rsm",
"version": "1.0.0",
"description": "React State Museum - Example of react-contextual",
"main": "src/index.js",
"keywords": [],
"dependencies": {
"packlist-components": "^1.2.0",
"react": "^16.3.2",
"react-contextual": "^5.0.1",
"react-dom": "^16.3.2",
"react-scripts": "^1.1.4"
},
"devDependencies": {},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
42 changes: 42 additions & 0 deletions React/react-contextual/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">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
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 App</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>
11 changes: 11 additions & 0 deletions React/react-contextual/src/Components/addItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";
import { AddPackingItem } from "packlist-components";

export default ({ addItem, clearItems, newItem, setNewItemText }) => (
<AddPackingItem
addItem={addItem}
setNewItemText={event => setNewItemText(event.target.value)}
value={newItem}
clear={clearItems}
/>
);
4 changes: 4 additions & 0 deletions React/react-contextual/src/Components/listItems.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import React from "react";
import { SimpleList } from "packlist-components";

export default ({ allItems }) => <SimpleList value={allItems} />;
34 changes: 34 additions & 0 deletions React/react-contextual/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/************************************************
* 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 { render } from "react-dom";
import { Provider, Subscribe } from "react-contextual";
import ListItems from "./Components/listItems";
import AddItems from "./Components/addItem";
import { store } from "./store";

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

render(
<Provider store={store}>
<Subscribe to={store}>
{props => (
<div style={styles}>
<h2>Welcome to react-contextual</h2>
<AddItems {...props} />
<ListItems {...props} />
</div>
)}
</Subscribe>
</Provider>,
document.getElementById("root")
);
14 changes: 14 additions & 0 deletions React/react-contextual/src/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createStore } from "react-contextual";

export const store = createStore({
newItem: "",
allItems: ["Hot Dog", "Pizza", "Donuts"],
setNewItemText: newItem => ({ newItem }),
addItem: () => state => ({
newItem: "",
allItems: state.allItems.concat([state.newItem])
}),
clearItems: () => state => ({
allItems: []
})
});
Loading