Play ground for Typescript with React & Redux
Inside Store folder we have all the reducers that are configured for Redux.
export interface IApplicationState {
chat: Chat.Types.IMessages, //Store/Chat
users: Users.Types.IUsers, //Store/Users
router: RouterState
}
export const reducers: Redux.Reducer<IApplicationState> = Redux.combineReducers<IApplicationState>({
chat: Chat.Reducer,
users: Users.Reducer,
router: routerReducer
})
So each one of them have one folder.
- Store/Chat
- Store/Users
- etc
Inside each folder we have 4 files, or more depending on how big-fat the reducers become.
- actions.ts
- index.ts
- reducers.ts
- types.ts
If we have many actions or reducers we can split them up in folders.
- Actions/index.ts
- Actions/LoadUsers.ts
- Actions/UpdateName.ts
- etc.
Read more: https://github.com/jamalsoueidan/react-redux-typescript/tree/master/src/Store
Component is very simple, they only accept props and actions!
Each folder have one component, and each component can have nested components if needed.
- Components/Chat
- Components/User
- Components/UsersList`
All components should be exported in Components/index
export { default as ComponentChat } from './Chat'
export { default as ComponentUser } from './User'
export { default as ComponentUsersList } from './UsersList'
This allow them to imported like this anywhere.
import { ComponentChat, ComponentUser, ComponentUsersList } from 'Components'
We are using [Component][Name], this way we always knows this is Component we are working with.
Pages act as containers, and each url route correspond to one page.
Pages are the only containers that connect to redux!
<Route path='/' component={PageApplication} />
Read more: https://github.com/jamalsoueidan/react-redux-typescript/tree/master/src/Pages
https://dev.to/resir014/a-type-safe-approach-to-redux-stores-in-typescript--5ajm
https://github.com/StevenIseki/react-router-redux-example
https://github.com/Microsoft/TypeScript-React-Starter#adding-a-reducer