This file contains hidden or 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
| import React from 'react' | |
| import {connect} from 'react-redux'; | |
| import {removeItem} from 'actions/itemsActions'; // -> export const deleteItem = (itemId) => ({type: 'DELETE_ITEM', payload: itemId}); | |
| export default class MyList extends Component { | |
| render() { | |
| return ( | |
| <div> | |
| {this.props.list.map(i => ( |
This file contains hidden or 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
| import React from 'react'; | |
| import {useSelector} from 'react-redux'; | |
| const MyList = () => { | |
| const list = useSelector(state => state.itemsList.items); | |
| return ( | |
| <ul> | |
| {props.list.map(i => <li key={i.id}>{i.name}</li>)} | |
| </ul> |
This file contains hidden or 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
| import React from 'react' | |
| import {connect} from 'react-redux'; | |
| export default class MyList extends Component { | |
| render() { | |
| return ( | |
| <ul> | |
| {this.props.list.map(i => <li key={i.id}>{i.name}</li>)} | |
| </ul> | |
| ) |
This file contains hidden or 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
| import React from 'react'; | |
| import ReactDOM from 'react-dom'; | |
| import App from './App'; | |
| import { createStore } from 'redux'; | |
| import { Provider } from 'react-redux'; | |
| import reducers from './reducers'; // these are our combined reducers | |
| const store = createStore(combinedReducers); | |
| ReactDOM.render( |
This file contains hidden or 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
| //in /reducer/index.js | |
| import itemsReducer from './itemsReducer'; | |
| import usersReducer from './userReducer'; | |
| //... | |
| import {combineReducer} from 'redux'; | |
| export default combineReducer({ | |
| itemsList: itemsReducer, |
This file contains hidden or 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
| //example of action creators | |
| export const addItem = (newItem) => ({type: 'ADD_ITEM', payload: newItem}); | |
| export const deleteItem = (itemId) => ({type: 'DELETE_ITEM', payload: itemId}); | |
| export const clearItems = () => ({type: 'CLEAR_ITEMS'}); |
This file contains hidden or 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
| //an ecample of reducer | |
| export default (state, action) => { | |
| const {type, payload} = action; | |
| switch (type){ | |
| case 'ADD_ITEM': | |
| return {...state, items: [...state.items, payload]}; | |
| case 'REMOVE_ITEM': | |
| const filteredItems = state.items.filter(i => i.id !== payload); | |
| return {...state, items: items}; |
This file contains hidden or 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
| import React from 'react'; | |
| import { Edit, SimpleForm, TextInput } from 'react-admin'; | |
| const NotesEdit = (props) => { | |
| return ( | |
| <Edit {...props}> | |
| <SimpleForm> | |
| <TextInput disabled source="id" /> | |
| <TextInput required source="text" /> | |
| </SimpleForm> | |
| </Edit> |
This file contains hidden or 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
| import React from 'react'; | |
| import { Create, SimpleForm, TextInput } from 'react-admin'; | |
| const NotesCreate = (props) => { | |
| return ( | |
| <Create {...props}> | |
| <SimpleForm> | |
| <TextInput source="text" required /> | |
| </SimpleForm> | |
| </Create> | |
| ); |
This file contains hidden or 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
| import React from 'react'; | |
| import { | |
| List, | |
| Datagrid, | |
| TextField, | |
| EditButton, | |
| DeleteButton, | |
| } from 'react-admin'; | |
| const NotesList = (props) => { |