Skip to content

Commit 4b189f7

Browse files
committed
feat: useRestate, useAction hooks
- Replaced CRA for parcel
1 parent f3549a9 commit 4b189f7

28 files changed

Lines changed: 9822 additions & 10348 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# App
2+
.cache
3+
dist
4+
15
# Logs
26
logs
37
*.log

example/App.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import { createStore } from 'redux';
4+
import Comp from './Comp';
5+
import { RestateProvider } from '../src';
6+
7+
const Actions = {
8+
INCREMENT: 'INCREMENT',
9+
DECREMENT: 'DECREMENT',
10+
};
11+
12+
const Reducer = (state: { count: number }, action: any) => {
13+
switch (action.type) {
14+
case Actions.INCREMENT:
15+
return {
16+
count: state.count + 1,
17+
};
18+
case Actions.DECREMENT:
19+
return {
20+
count: state.count - 1,
21+
};
22+
default:
23+
return state;
24+
}
25+
};
26+
27+
const store = createStore(Reducer, { count: 3 });
28+
29+
export default function App() {
30+
return (
31+
<RestateProvider value={store}>
32+
<Comp />
33+
</RestateProvider>
34+
);
35+
}

example/Comp.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
import { useRestate, useAction } from '../src';
3+
4+
export default function Component() {
5+
const [restate, dispatch] = useRestate((state: { count: number }) => {
6+
return { count: state.count };
7+
});
8+
9+
const incrementAction = { type: 'INCREMENT' };
10+
const increment = useAction(incrementAction);
11+
12+
return (
13+
<div>
14+
<p>{restate.count}</p>
15+
<a onClick={increment}>Increment count</a>
16+
<a onClick={() => dispatch({ type: 'DECREMENT' })}>Decrement count</a>
17+
</div>
18+
);
19+
}

example/__tests__/App.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import App from '../App';
4+
5+
it('renders without crashing', () => {
6+
const div = document.createElement('div');
7+
ReactDOM.render(<App />, div);
8+
ReactDOM.unmountComponentAtNode(div);
9+
});

example/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<title>useRestate</title>
7+
</head>
8+
<body>
9+
<noscript>
10+
You need to enable JavaScript to run this app.
11+
</noscript>
12+
<div id="root"></div>
13+
<script src="./index.tsx"></script>
14+
</body>
15+
</html>

example/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import { createStore } from 'redux';
4+
import App from './App';
5+
6+
ReactDOM.render(<App />, document.getElementById('root'));

example/package.json

Lines changed: 0 additions & 33 deletions
This file was deleted.

example/public/favicon.ico

-3.78 KB
Binary file not shown.

example/public/index.html

Lines changed: 0 additions & 40 deletions
This file was deleted.

example/public/manifest.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)