-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: initial redux store & useRestate
- Loading branch information
Showing
8 changed files
with
124 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,14 @@ | ||
import React, { Component } from 'react'; | ||
import React from 'react'; | ||
import { useRestate } from '../..'; | ||
|
||
class App extends Component { | ||
public render() { | ||
return ( | ||
<div className="App"> | ||
<header className="App-header"> | ||
<p> | ||
Edit <code>src/App.tsx</code> and save to reload. | ||
</p> | ||
<a | ||
className="App-link" | ||
href="https://reactjs.org" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Learn React | ||
</a> | ||
</header> | ||
</div> | ||
); | ||
} | ||
} | ||
export default function Component() { | ||
const [restate, dispatch] = useRestate((state: any) => { | ||
return { count: state.count }; | ||
}); | ||
|
||
export default App; | ||
return ( | ||
<div> | ||
<p>Hey</p> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { createStore } from 'redux'; | ||
import './index.css'; | ||
import App from './App'; | ||
import * as serviceWorker from './serviceWorker'; | ||
import { RestateProvider } from '../../'; | ||
const Actions = { | ||
TOGGLE_MENU: 'TOGGLE_MENU', | ||
}; | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')); | ||
const Reducer = (state = {}, action: any) => { | ||
switch (action.type) { | ||
case Actions.TOGGLE_MENU: | ||
break; | ||
default: | ||
return state; | ||
} | ||
return state; | ||
}; | ||
|
||
const store = createStore(Reducer); | ||
|
||
ReactDOM.render( | ||
<RestateProvider value={store}> | ||
<App /> | ||
</RestateProvider>, | ||
document.getElementById('root'), | ||
); | ||
|
||
serviceWorker.register(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, { useState, useContext, useEffect, useRef } from 'react'; | ||
import { Action, Dispatch, Store } from 'redux'; | ||
|
||
const RestateContext: React.Context<Store<any> | null> = React.createContext(null); | ||
|
||
export const RestateProvider = RestateContext.Provider; | ||
|
||
export function useRestate<T, U>(selector: any) { | ||
const store = useContext(RestateContext); | ||
const restate: T = null; | ||
console.log(store, selector); | ||
|
||
return [restate, store.dispatch]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,16 @@ | |
"repository": "https://github.com/animify/useRestate.git", | ||
"author": "Stefan Mansson <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"react": "^16.7.0-alpha.2", | ||
"redux": "^4.0.1" | ||
}, | ||
"scripts": { | ||
"release": "changelog && git push --follow-tags && yarn publish --access public --non-interactive", | ||
"lint": "tslint -p tsconfig.json" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^16.7.11", | ||
"changelog.md": "^1.1.0", | ||
"husky": "^1.2.0", | ||
"lint-staged": "^8.1.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters