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
| // Functional compoennt | |
| function App() { | |
| return ( | |
| <Fragment> | |
| <Router> | |
| <Switch> | |
| <Route path="/list" exact={true} component={List} /> | |
| <Route path="/list/:id" exact={true} component={View} /> | |
| <Redirect from="/" to="/list" /> | |
| <Route path="*" exact={true} component={List} /> |
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
| // Functional component | |
| function Filter(props) { | |
| const [keyword, setKeyword] = useState(''); | |
| console.log(props) | |
| // ... | |
| } | |
| // class based component | |
| class Filter extends Component { | |
| constructor(props) { |
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 { GET_CONTACTS, IS_SORTED } from './types'; | |
| import { User } from '../../models/user'; | |
| export const contactList = (contacts: User[]) => { | |
| return { | |
| type: GET_CONTACTS, | |
| data: contacts | |
| } | |
| } | |
| export const isSorted = (data: boolean) => { |
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 { ActionModel } from "../../models/action"; | |
| export function contacts (state = [], action: ActionModel) { | |
| switch (action.type) { | |
| case "GET_CONTACTS": | |
| return action.data | |
| default: | |
| return state; | |
| } | |
| } |
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
| useEffect(() => { | |
| console.log('List Mounted') | |
| if (!contacts.length) { | |
| fetchContacts(); | |
| } | |
| return function () { | |
| console.log('List Unmounted') | |
| } | |
| }, []) |
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
| function handleInput(input: string) { | |
| setKeyword(input) | |
| if (input) { | |
| props.onChange(input); | |
| } else { | |
| props.onChange('') | |
| } | |
| } | |
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
| function handleInput(input: string) { | |
| setKeyword(input) | |
| if (input) { | |
| props.onChange(input); | |
| } else { | |
| props.onChange('') | |
| } | |
| } | |
| <Fragment> |
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 axios from "axios"; | |
| const API = { | |
| backend: "https://randomuser.me/api/", | |
| }; | |
| export const fetchUsers = async () => { | |
| let res = await axios.get(API.backend + '?inc=name,phone&results=20&nat=us'); | |
| try { | |
| return res.data.results |
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
| let car1 = { | |
| color: 'Red', | |
| company: 'Ferrari', | |
| }; | |
| let car2 = { | |
| color: 'Blue', | |
| company: 'BMW', | |
| }; |
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
| const routes = ['home', 'grids', 'grid1']; | |
| const breadcrumbs = []; | |
| let level = 0; | |
| while(level < routes.length) { | |
| breadcrumbs.push(routeTitleLink(routes.slice(0, level+1))); // calling recursive function for each route. | |
| level++ | |
| } | |
| console.log(breadcrumbs) |
OlderNewer