Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
docs: updated readme with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniAkash committed Sep 11, 2020
1 parent eb50fde commit 7cb535a
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 12 deletions.
7 changes: 4 additions & 3 deletions README.md
@@ -1,7 +1,7 @@
<div align="center">

<img
src="https://github.com/DaniAkash/rex-state/raw/bob/assets/logo.png"
src="https://github.com/react-native-toolkit/rex-state/raw/master/assets/logo.png"
alt="rex-state-logo"
height="100px"
width="100px"
Expand Down Expand Up @@ -34,7 +34,7 @@ Convert hooks into shared states between react components
- 📑 [Documentation][storybook-url]
- 👨🏽‍🏫 Examples
- [Simple Counter][codesandbox-example] with React.js on CodeSandbox
- [Dark Mode] with React Native on expo. Project in `example/` directory
- [Dark Mode][expo-app] with React Native on expo. Project in [`example/`](https://github.com/react-native-toolkit/rex-state/tree/master/example) directory
-[Why Rex State?](#why-rex-state)

## Motivation
Expand Down Expand Up @@ -123,11 +123,12 @@ MIT © [DaniAkash][twitter]
[codesandbox-example]: https://codesandbox.io/s/rex-counter-2m4zy?file=/src/App.js
[storybook-url]: https://rex-state.netlify.app
[expo-app]: https://expo.io/@daniakash/rex-state-example
[build]: https://github.com/react-native-toolkit/rex-state/actions
[build-badge]: https://github.com/react-native-toolkit/rex-state/workflows/build/badge.svg
[coverage-badge]: https://api.codeclimate.com/v1/badges/9bd775907eca8a3dbab3/test_coverage
[coverage-url]: https://codeclimate.com/github/react-native-toolkit/rex-state/test_coverage
[maintainability-badge]: https://api.codeclimate.com/v1/badges/f7954c1e1686cabeeb97/maintainability
[maintainability-badge]: https://api.codeclimate.com/v1/badges/9bd775907eca8a3dbab3/maintainability
[maintainability-url]: https://codeclimate.com/github/react-native-toolkit/rex-state/maintainability
[bundle-phobia-badge]: https://badgen.net/bundlephobia/minzip/rex-state
[bundle-phobia]: https://bundlephobia.com/result?p=rex-state
Expand Down
2 changes: 0 additions & 2 deletions example/src/stories/API.stories.mdx
Expand Up @@ -2,8 +2,6 @@ import { Meta } from '@storybook/addon-docs/blocks';

<Meta title="Intro/API" />

<!-- -->

## `createRexStore`

```tsx
Expand Down
62 changes: 62 additions & 0 deletions example/src/stories/Counter.tsx
@@ -0,0 +1,62 @@
import React, { useState } from 'react';
import { createRexStore } from 'rex-state';

const useCounterHook = (initialCount?: number) => {
const [count, setCount] = useState(initialCount || 0);

const increaseCount = () => setCount(count + 1);
const decreaseCount = () => setCount(count - 1);

return {
count,
increaseCount,
decreaseCount,
};
};

const { useStore: useCounter, RexProvider: CountProvider } = createRexStore(
useCounterHook
);

const CountDisplay = () => {
const { count } = useCounter();

return <h1>{count}</h1>;
};

const Controls = () => {
const { increaseCount, decreaseCount } = useCounter();

return (
<>
<button onClick={decreaseCount}>
<span role="img" aria-label="subtract">
</span>
</button>
<button onClick={increaseCount}>
<span role="img" aria-label="add">
</span>
</button>
</>
);
};

export const CounterWithInitialValue = () => {
return (
<CountProvider value={10}>
<CountDisplay />
<Controls />
</CountProvider>
);
};

export const CounterWithoutInitialValue = () => {
return (
<CountProvider>
<CountDisplay />
<Controls />
</CountProvider>
);
};
13 changes: 13 additions & 0 deletions example/src/stories/CounterWithInitialValue.stories.tsx
@@ -0,0 +1,13 @@
import React from 'react';
import type { Story, Meta } from '@storybook/react/types-6-0';
import { CounterWithInitialValue } from './Counter';

export default {
title: 'Example/Counter with Initial Value',
component: CounterWithInitialValue,
} as Meta;

const Template: Story<{}> = (args) => <CounterWithInitialValue {...args} />;

export const WithInitialValue = Template.bind({});
WithInitialValue.args = {};
13 changes: 13 additions & 0 deletions example/src/stories/CounterWithoutInitialValue.stories.tsx
@@ -0,0 +1,13 @@
import React from 'react';
import type { Story, Meta } from '@storybook/react/types-6-0';
import { CounterWithoutInitialValue } from './Counter';

export default {
title: 'Example/Counter without Initial Value',
component: CounterWithoutInitialValue,
} as Meta;

const Template: Story<{}> = (args) => <CounterWithoutInitialValue {...args} />;

export const WithoutInitialValue = Template.bind({});
WithoutInitialValue.args = {};
14 changes: 7 additions & 7 deletions example/src/stories/GettingStarted.stories.mdx
Expand Up @@ -6,7 +6,7 @@ import { Text } from 'react-native';
<Meta title="Intro/Getting Started" />

<img
src="https://github.com/DaniAkash/rex-state/raw/bob/assets/logo.png"
src="https://github.com/react-native-toolkit/rex-state/raw/master/assets/logo.png"
alt="rex-state-logo"
height="100px"
width="100px"
Expand Down Expand Up @@ -93,12 +93,12 @@ const ThemeText = () => {
<ThemeText />
</DarkModeProvider>
[build]: https://github.com/DaniAkash/rex-state/actions
[build-badge]: https://github.com/daniakash/rex-state/workflows/build/badge.svg
[coverage-badge]: https://api.codeclimate.com/v1/badges/f7954c1e1686cabeeb97/test_coverage
[coverage-url]: https://codeclimate.com/github/DaniAkash/rex-state/test_coverage
[maintainability-badge]: https://api.codeclimate.com/v1/badges/f7954c1e1686cabeeb97/maintainability
[maintainability-url]: https://codeclimate.com/github/DaniAkash/rex-state/maintainability
[build]: https://github.com/react-native-toolkit/rex-state/actions
[build-badge]: https://github.com/react-native-toolkit/rex-state/workflows/build/badge.svg
[coverage-badge]: https://api.codeclimate.com/v1/badges/9bd775907eca8a3dbab3/test_coverage
[coverage-url]: https://codeclimate.com/github/react-native-toolkit/rex-state/test_coverage
[maintainability-badge]: https://api.codeclimate.com/v1/badges/9bd775907eca8a3dbab3/maintainability
[maintainability-url]: https://codeclimate.com/github/react-native-toolkit/rex-state/maintainability
[bundle-phobia-badge]: https://badgen.net/bundlephobia/minzip/rex-state
[bundle-phobia]: https://bundlephobia.com/result?p=rex-state
[downloads-badge]: https://img.shields.io/npm/dm/rex-state.svg
Expand Down

0 comments on commit 7cb535a

Please sign in to comment.