├── .gitignore ├── README.md ├── examples ├── .gitkeep └── cra-ts │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt │ ├── src │ ├── App.css │ ├── App.test.tsx │ ├── App.tsx │ ├── components │ │ ├── Basic.tsx │ │ ├── Counter.js │ │ ├── CounterTS.tsx │ │ ├── User.tsx │ │ └── Wrapper.tsx │ ├── index.css │ ├── index.tsx │ ├── logo.svg │ ├── react-app-env.d.ts │ ├── serviceWorker.ts │ └── setupTests.ts │ ├── tsconfig.json │ └── yarn.lock ├── web ├── .gitignore ├── README.md ├── babel.config.js ├── docs │ ├── 1-intro.mdx │ ├── 2-component.mdx │ ├── 3-hook.mdx │ ├── 4.context.mdx │ ├── 5.StyleCSS.mdx │ ├── 6.Tips & Patterns.mdx │ └── ref.md ├── docusaurus.config.js ├── package.json ├── sidebars.js ├── src │ ├── css │ │ └── custom.css │ └── pages │ │ └── styles.module.css ├── static │ ├── .nojekyll │ └── img │ │ ├── favicon.ico │ │ ├── logo.svg │ │ ├── undraw_docusaurus_mountain.svg │ │ ├── undraw_docusaurus_react.svg │ │ └── undraw_docusaurus_tree.svg └── yarn.lock └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | /sample/cra-ts -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Panduan Typescript untuk Developer React 2 | 3 | React dan Typescript adalah dua teknologi yang semakin populer di kalangan developer react. 4 | Typescript membuat pengembangan aplikasi react lebih scalable, dan mudah untuk maintenance. Tidak heran jika typescript 5 | banyak digunakan untuk aplikasi yang cukup kompleks atau codebase yang besar. 6 | 7 | Meskipun kedua teknologi sudah teruji dan punya banyak benefit tapi terkadang 8 | pada saat proses implementasi dan belajar tidak bisa di bilang mudah cenderung rumit 9 | di awal. Kesulitan di awal apalagi untuk hal yang baru itu hal yang wajar. 10 | 11 | Panduan Typescript untuk Developer ini di bagi ke beberapa chapter, dan setiap chapter dilengkapi dengan contoh source code, 12 | video, dan tulisan. 13 | 14 | 1. **Component:** Menulis functional dan class component dengan typescript 15 | 2. **Hook :** Memaksimalkan penggunaan hook dengan typescript 16 | 3. **Context :** React Context API untuk manajemen global state 17 | 4. **Style & CSS :** CSSinJS membuat penulisan style lebih baik 18 | 5. **Tips & Patterns :** Kumpulan tips, patterns dan best practices 19 | -------------------------------------------------------------------------------- /examples/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SastraNababan/react-ts/44c81fa21432af21cb04172a09d311d57f3f10c7/examples/.gitkeep -------------------------------------------------------------------------------- /examples/cra-ts/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /examples/cra-ts/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `yarn start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `yarn test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `yarn build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `yarn eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | -------------------------------------------------------------------------------- /examples/cra-ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cra-ts", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^4.2.4", 7 | "@testing-library/react": "^9.3.2", 8 | "@testing-library/user-event": "^7.1.2", 9 | "@types/jest": "^24.0.0", 10 | "@types/node": "^12.0.0", 11 | "@types/react": "^16.9.0", 12 | "@types/react-dom": "^16.9.0", 13 | "prop-types": "^15.7.2", 14 | "react": "^16.14.0", 15 | "react-dom": "^16.14.0", 16 | "react-scripts": "3.4.3", 17 | "typescript": "~3.7.2" 18 | }, 19 | "scripts": { 20 | "start": "react-scripts start", 21 | "build": "react-scripts build", 22 | "test": "react-scripts test", 23 | "eject": "react-scripts eject" 24 | }, 25 | "eslintConfig": { 26 | "extends": "react-app" 27 | }, 28 | "browserslist": { 29 | "production": [ 30 | ">0.2%", 31 | "not dead", 32 | "not op_mini all" 33 | ], 34 | "development": [ 35 | "last 1 chrome version", 36 | "last 1 firefox version", 37 | "last 1 safari version" 38 | ] 39 | }, 40 | "devDependencies": { 41 | "@types/prop-types": "^15.7.3" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /examples/cra-ts/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SastraNababan/react-ts/44c81fa21432af21cb04172a09d311d57f3f10c7/examples/cra-ts/public/favicon.ico -------------------------------------------------------------------------------- /examples/cra-ts/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /examples/cra-ts/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SastraNababan/react-ts/44c81fa21432af21cb04172a09d311d57f3f10c7/examples/cra-ts/public/logo192.png -------------------------------------------------------------------------------- /examples/cra-ts/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SastraNababan/react-ts/44c81fa21432af21cb04172a09d311d57f3f10c7/examples/cra-ts/public/logo512.png -------------------------------------------------------------------------------- /examples/cra-ts/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /examples/cra-ts/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /examples/cra-ts/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/cra-ts/src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | const { getByText } = render(); 7 | const linkElement = getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /examples/cra-ts/src/App.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | // import logo from "./logo.svg"; 3 | import "./App.css"; 4 | import Basic from "./components/Basic"; 5 | import User from "./components/User"; 6 | import CounterJS from "./components/Counter"; 7 | import CounterTS from "./components/CounterTS"; 8 | import Wrapper from "./components/Wrapper"; 9 | 10 | function App() { 11 | return ( 12 |
13 |
14 | {/* logo 15 |

16 | Edit src/App.tsx and save to reload. 17 |

18 | 24 | Learn React 25 | */} 26 | 27 | 28 |

Children

29 |
30 | 31 | {/* */} 32 | 33 | 34 |
35 |
36 |
37 | ); 38 | } 39 | 40 | export default App; 41 | -------------------------------------------------------------------------------- /examples/cra-ts/src/components/Basic.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC, FunctionComponent } from "react"; 2 | 3 | type Props = { 4 | name: string; 5 | active?: boolean; 6 | children: React.ReactNode; 7 | }; 8 | 9 | function Basic({ name, active = false, children }: Props) { 10 | return

asdfdasf

; 11 | } 12 | 13 | export default Basic; 14 | -------------------------------------------------------------------------------- /examples/cra-ts/src/components/Counter.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | // import PropTypes from "prop-types"; 3 | 4 | function CounterJS(props) { 5 | return ( 6 |
7 |

Counter Value (JS) = {props.value + 1}

8 |
9 | ); 10 | } 11 | 12 | // CounterJS.propTypes = { 13 | // value: PropTypes.number.isRequired, 14 | // }; 15 | export default CounterJS; 16 | -------------------------------------------------------------------------------- /examples/cra-ts/src/components/CounterTS.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC, useState } from "react"; 2 | import PropTypes, { InferProps } from "prop-types"; 3 | 4 | type Props = { 5 | value: number; 6 | caption?: string; 7 | }; 8 | 9 | // function CounterTS(props: InferProps) { 10 | function CounterTS(props: Props) { 11 | // const CounterTS = (props: Props) => { 12 | // const CounterTS: FC = (props) => { 13 | 14 | const [val, setVal] = useState(0); 15 | 16 | return ( 17 |
18 |

19 | {props.caption ? props.caption : "Counter Value (TS) ="} 20 | {val} 21 | 22 |

23 |
24 | ); 25 | } 26 | 27 | CounterTS.defaultProps = { 28 | value: 0, 29 | }; 30 | 31 | CounterTS.propTypes = { 32 | value: PropTypes.number.isRequired, 33 | caption: PropTypes.string, 34 | }; 35 | 36 | export default CounterTS; 37 | -------------------------------------------------------------------------------- /examples/cra-ts/src/components/User.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | 3 | interface Props { 4 | name: string; 5 | active?: boolean; 6 | note?: string; 7 | } 8 | interface State { 9 | online: boolean; 10 | } 11 | 12 | export default class User extends Component { 13 | static defaultProps = { 14 | active: false, 15 | note: "test 123", 16 | }; 17 | 18 | public readonly state: Readonly = { 19 | online: false, 20 | }; 21 | 22 | render() { 23 | return ( 24 | <> 25 |

26 | {" "} 27 | Hello {this.props.name} {this.props.note}{" "} 28 |

29 | {this.state.online &&

Online

} 30 | 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /examples/cra-ts/src/components/Wrapper.tsx: -------------------------------------------------------------------------------- 1 | import React, { FunctionComponent, ReactNode } from "react"; 2 | 3 | // #1 4 | // type Props = { 5 | // children: ReactNode; 6 | // className: string; 7 | // }; 8 | // const Wrapper = (props: Props) => { 9 | // return
{props.children}
; 10 | // }; 11 | 12 | // #2 13 | type Props = { 14 | note?: string; 15 | }; 16 | const Wrapper: FunctionComponent = (props) => { 17 | return
{props.children}
; 18 | }; 19 | 20 | export default Wrapper; 21 | -------------------------------------------------------------------------------- /examples/cra-ts/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /examples/cra-ts/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want your app to work offline and load faster, you can change 15 | // unregister() to register() below. Note this comes with some pitfalls. 16 | // Learn more about service workers: https://bit.ly/CRA-PWA 17 | serviceWorker.unregister(); 18 | -------------------------------------------------------------------------------- /examples/cra-ts/src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /examples/cra-ts/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /examples/cra-ts/src/serviceWorker.ts: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.0/8 are considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | type Config = { 24 | onSuccess?: (registration: ServiceWorkerRegistration) => void; 25 | onUpdate?: (registration: ServiceWorkerRegistration) => void; 26 | }; 27 | 28 | export function register(config?: Config) { 29 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 30 | // The URL constructor is available in all browsers that support SW. 31 | const publicUrl = new URL( 32 | process.env.PUBLIC_URL, 33 | window.location.href 34 | ); 35 | if (publicUrl.origin !== window.location.origin) { 36 | // Our service worker won't work if PUBLIC_URL is on a different origin 37 | // from what our page is served on. This might happen if a CDN is used to 38 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 39 | return; 40 | } 41 | 42 | window.addEventListener('load', () => { 43 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 44 | 45 | if (isLocalhost) { 46 | // This is running on localhost. Let's check if a service worker still exists or not. 47 | checkValidServiceWorker(swUrl, config); 48 | 49 | // Add some additional logging to localhost, pointing developers to the 50 | // service worker/PWA documentation. 51 | navigator.serviceWorker.ready.then(() => { 52 | console.log( 53 | 'This web app is being served cache-first by a service ' + 54 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 55 | ); 56 | }); 57 | } else { 58 | // Is not localhost. Just register service worker 59 | registerValidSW(swUrl, config); 60 | } 61 | }); 62 | } 63 | } 64 | 65 | function registerValidSW(swUrl: string, config?: Config) { 66 | navigator.serviceWorker 67 | .register(swUrl) 68 | .then(registration => { 69 | registration.onupdatefound = () => { 70 | const installingWorker = registration.installing; 71 | if (installingWorker == null) { 72 | return; 73 | } 74 | installingWorker.onstatechange = () => { 75 | if (installingWorker.state === 'installed') { 76 | if (navigator.serviceWorker.controller) { 77 | // At this point, the updated precached content has been fetched, 78 | // but the previous service worker will still serve the older 79 | // content until all client tabs are closed. 80 | console.log( 81 | 'New content is available and will be used when all ' + 82 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 83 | ); 84 | 85 | // Execute callback 86 | if (config && config.onUpdate) { 87 | config.onUpdate(registration); 88 | } 89 | } else { 90 | // At this point, everything has been precached. 91 | // It's the perfect time to display a 92 | // "Content is cached for offline use." message. 93 | console.log('Content is cached for offline use.'); 94 | 95 | // Execute callback 96 | if (config && config.onSuccess) { 97 | config.onSuccess(registration); 98 | } 99 | } 100 | } 101 | }; 102 | }; 103 | }) 104 | .catch(error => { 105 | console.error('Error during service worker registration:', error); 106 | }); 107 | } 108 | 109 | function checkValidServiceWorker(swUrl: string, config?: Config) { 110 | // Check if the service worker can be found. If it can't reload the page. 111 | fetch(swUrl, { 112 | headers: { 'Service-Worker': 'script' } 113 | }) 114 | .then(response => { 115 | // Ensure service worker exists, and that we really are getting a JS file. 116 | const contentType = response.headers.get('content-type'); 117 | if ( 118 | response.status === 404 || 119 | (contentType != null && contentType.indexOf('javascript') === -1) 120 | ) { 121 | // No service worker found. Probably a different app. Reload the page. 122 | navigator.serviceWorker.ready.then(registration => { 123 | registration.unregister().then(() => { 124 | window.location.reload(); 125 | }); 126 | }); 127 | } else { 128 | // Service worker found. Proceed as normal. 129 | registerValidSW(swUrl, config); 130 | } 131 | }) 132 | .catch(() => { 133 | console.log( 134 | 'No internet connection found. App is running in offline mode.' 135 | ); 136 | }); 137 | } 138 | 139 | export function unregister() { 140 | if ('serviceWorker' in navigator) { 141 | navigator.serviceWorker.ready 142 | .then(registration => { 143 | registration.unregister(); 144 | }) 145 | .catch(error => { 146 | console.error(error.message); 147 | }); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /examples/cra-ts/src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom/extend-expect'; 6 | -------------------------------------------------------------------------------- /examples/cra-ts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "module": "esnext", 16 | "moduleResolution": "node", 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "noEmit": true, 20 | "jsx": "react" 21 | }, 22 | "include": [ 23 | "src" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /web/.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | /node_modules 3 | 4 | # Production 5 | /build 6 | 7 | # Generated files 8 | .docusaurus 9 | .cache-loader 10 | 11 | # Misc 12 | .DS_Store 13 | .env.local 14 | .env.development.local 15 | .env.test.local 16 | .env.production.local 17 | 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* 21 | -------------------------------------------------------------------------------- /web/README.md: -------------------------------------------------------------------------------- 1 | # Website 2 | 3 | This website is built using [Docusaurus 2](https://v2.docusaurus.io/), a modern static website generator. 4 | 5 | ## Installation 6 | 7 | ```console 8 | yarn install 9 | ``` 10 | 11 | ## Local Development 12 | 13 | ```console 14 | yarn start 15 | ``` 16 | 17 | This command starts a local development server and open up a browser window. Most changes are reflected live without having to restart the server. 18 | 19 | ## Build 20 | 21 | ```console 22 | yarn build 23 | ``` 24 | 25 | This command generates static content into the `build` directory and can be served using any static contents hosting service. 26 | 27 | ## Deployment 28 | 29 | ```console 30 | GIT_USER= USE_SSH=true yarn deploy 31 | ``` 32 | 33 | If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. 34 | -------------------------------------------------------------------------------- /web/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [require.resolve('@docusaurus/core/lib/babel/preset')], 3 | }; 4 | -------------------------------------------------------------------------------- /web/docs/1-intro.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: intro 3 | title: Intro 4 | sidebar_label: Intro 5 | slug: / 6 | --- 7 | 8 | React dan Typescript adalah dua teknologi yang semakin populer di kalangan developer react. 9 | Typescript membuat pengembangan aplikasi react lebih scalable, dan mudah untuk maintenance. Tidak heran jika typescript 10 | banyak digunakan untuk aplikasi yang cukup kompleks atau codebase yang besar. 11 | 12 | Meskipun kedua teknologi sudah teruji dan punya banyak benefit tapi terkadang 13 | pada saat proses implementasi dan belajar tidak bisa di bilang mudah cenderung rumit 14 | di awal. Kesulitan di awal apalagi untuk hal yang baru itu hal yang wajar. 15 | 16 | Panduan Typescript untuk Developer ini di bagi ke beberapa chapter, dan setiap chapter dilengkapi dengan contoh source code, 17 | video, dan tulisan. 18 | 19 | 1. **Component:** Menulis functional dan class component dengan typescript 20 | 2. **Hook :** Memaksimalkan penggunaan hook dengan typescript 21 | 3. **Context :** React Context API untuk manajemen global state 22 | 4. **Style & CSS :** CSSinJS membuat penulisan style lebih baik 23 | 5. **Tips & Patterns :** Kumpulan tips, patterns dan best practices 24 | -------------------------------------------------------------------------------- /web/docs/2-component.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: component 3 | title: Component 4 | sidebar_label: Component 5 | --- 6 | 7 | 8 | ## Function Component 9 | 10 | ### Component Sederhana 11 | Untuk function component yang tidak memiliki props, caranya sama saja seperti di javascript. 12 | Tidak wajib ada definisi type. 13 | 14 | ```tsx 15 | function Hello(){ 16 | return

Hello

17 | } 18 | ``` 19 | 20 | ### Props 21 | Untuk defenisi props bisa menggunakan `type` atau `interface` 22 | ```tsx 23 | type MyProps = { 24 | name: string 25 | } 26 | 27 | function Hello(props:MyProps){ 28 | return

Hello {props.name}

29 | } 30 | ``` 31 | 32 | ### Default Props 33 | Untuk defenisi props bisa menggunakan `type` atau `interface` 34 | ```tsx 35 | type MyProps = { 36 | name: string, 37 | active?: boolean, 38 | } 39 | 40 | function Hello({name, active = false}:MyProps){ 41 | return

Hello {props.name}

42 | } 43 | ``` 44 | 45 | ### Children 46 | ```tsx 47 | type MyProps = { 48 | name: string, 49 | active?: boolean, 50 | children: React.ReactNode 51 | } 52 | 53 | function Hello({name, active = false, children}:MyProps){ 54 | return ( 55 |
56 |

Hello {props.name}

57 | {children} 58 |
59 | ) 60 | } 61 | ``` 62 | 63 | 64 | ## Class Component 65 | 66 | ### Props & State 67 | ```tsx 68 | interface Props { 69 | name: string; 70 | active?: boolean; 71 | note?: string; 72 | } 73 | 74 | interface State { 75 | online: boolean; 76 | } 77 | 78 | export default class User extends Component { 79 | render() { 80 | return ( 81 | <> 82 |

Hello, {this.props.name}

83 |

Note: {this.props.note}

84 | 85 | ); 86 | } 87 | } 88 | 89 | ``` 90 | 91 | 92 | 93 | ### Default Props & State 94 | ```tsx 95 | interface Props { 96 | name: string; 97 | active?: boolean; 98 | note?: string; 99 | } 100 | 101 | interface State { 102 | online: boolean; 103 | } 104 | 105 | static defaultProps = { 106 | active: false, 107 | note: "default note", 108 | }; 109 | 110 | public readonly state: Readonly = { 111 | online: false, 112 | }; 113 | 114 | export default class User extends Component { 115 | render() { 116 | return ( 117 | <> 118 |

Hello, {this.props.name}

119 |

Note: {this.props.note}

120 | {this.state.online &&

Online

} 121 | 122 | ); 123 | } 124 | } 125 | 126 | ``` 127 | 128 | ## Type vs Interface 129 | 130 | ## React.FC vs Normal Function 131 | Terkadang Function Component di defenisikan dengan *generic* type `FunctionComponent` atau 132 | versi singkatnya `FC` 133 | 134 | ```tsx 135 | import React, { FC, FunctionComponent } from "react"; 136 | 137 | function Hello:FC(){ 138 | return

Hello React Typescript

139 | } 140 | ``` 141 | 142 | 143 | -------------------------------------------------------------------------------- /web/docs/3-hook.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: hook 3 | title: Hook 4 | sidebar_label: Hook 5 | --- 6 | 7 | ``` Sedang Dalam Pengerjaan ``` -------------------------------------------------------------------------------- /web/docs/4.context.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: context 3 | title: Context 4 | sidebar_label: Context 5 | --- 6 | 7 | ``` Sedang Dalam Pengerjaan ``` -------------------------------------------------------------------------------- /web/docs/5.StyleCSS.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: stylecss 3 | title: Style & CSS 4 | sidebar_label: Style & CSS 5 | --- 6 | 7 | ``` Sedang Dalam Pengerjaan ``` -------------------------------------------------------------------------------- /web/docs/6.Tips & Patterns.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: patterns 3 | title: Tips & Patterns 4 | sidebar_label: Tips & Patterns 5 | --- 6 | 7 | ``` Sedang Dalam Pengerjaan ``` -------------------------------------------------------------------------------- /web/docs/ref.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: ref 3 | title: Referensi 4 | sidebar_label: Referensi 5 | --- 6 | 7 | ``` Sedang Dalam Pengerjaan `` -------------------------------------------------------------------------------- /web/docusaurus.config.js: -------------------------------------------------------------------------------- 1 | const rehypeTruncate = require("rehype-truncate"); 2 | const remarkImages = require("remark-images"); 3 | const remarkOembed = require("@agentofuser/remark-oembed"); 4 | const oembed = require("@agentofuser/remark-oembed"); 5 | module.exports = { 6 | title: "Panduan Typescript untuk Developer React", 7 | tagline: "", 8 | url: "https://react-ts-wine.vercel.app/", 9 | baseUrl: "/", 10 | onBrokenLinks: "throw", 11 | favicon: "img/favicon.ico", 12 | organizationName: "SastraNababan", // Usually your GitHub org/user name. 13 | projectName: "react-ts", // Usually your repo name. 14 | themeConfig: { 15 | navbar: { 16 | title: "React TS", 17 | logo: { 18 | alt: "My Site Logo", 19 | src: "img/logo.svg", 20 | }, 21 | items: [ 22 | { 23 | to: "/", 24 | activeBasePath: "start", 25 | label: "Mulai", 26 | position: "left", 27 | }, 28 | // { to: "blog", label: "Blog", position: "left" }, 29 | { 30 | href: "https://github.com/SastraNababan/react-ts", 31 | label: "GitHub", 32 | position: "right", 33 | }, 34 | ], 35 | }, 36 | footer: { 37 | style: "dark", 38 | copyright: `Panduan Typescript untuk Developer React. Built with Docusaurus.`, 39 | }, 40 | }, 41 | presets: [ 42 | [ 43 | "@docusaurus/preset-classic", 44 | { 45 | docs: { 46 | routeBasePath: "/", 47 | sidebarPath: require.resolve("./sidebars.js"), 48 | editUrl: 49 | "https://github.com/facebook/docusaurus/edit/master/website/", 50 | remarkPlugins: [remarkImages, remarkOembed], 51 | rehypePlugins: [rehypeTruncate], 52 | }, 53 | // blog: { 54 | // showReadingTime: true, 55 | // // Please change this to your repo. 56 | // editUrl: 57 | // "https://github.com/facebook/docusaurus/edit/master/website/blog/", 58 | // }, 59 | theme: { 60 | customCss: require.resolve("./src/css/custom.css"), 61 | }, 62 | }, 63 | ], 64 | ], 65 | }; 66 | -------------------------------------------------------------------------------- /web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "docusaurus": "docusaurus", 7 | "start": "docusaurus start", 8 | "build": "docusaurus build", 9 | "swizzle": "docusaurus swizzle", 10 | "deploy": "docusaurus deploy", 11 | "serve": "docusaurus serve" 12 | }, 13 | "dependencies": { 14 | "@agentofuser/remark-oembed": "^1.0.4", 15 | "@docusaurus/core": "2.0.0-alpha.66", 16 | "@docusaurus/preset-classic": "2.0.0-alpha.66", 17 | "@mdx-js/react": "^1.5.8", 18 | "clsx": "^1.1.1", 19 | "react": "^16.8.4", 20 | "react-dom": "^16.8.4", 21 | "rehype-truncate": "^1.2.1", 22 | "remark-images": "^2.0.0" 23 | }, 24 | "browserslist": { 25 | "production": [ 26 | ">0.2%", 27 | "not dead", 28 | "not op_mini all" 29 | ], 30 | "development": [ 31 | "last 1 chrome version", 32 | "last 1 firefox version", 33 | "last 1 safari version" 34 | ] 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /web/sidebars.js: -------------------------------------------------------------------------------- 1 | // module.exports = { 2 | // someSidebar: { 3 | // Intro: { 4 | // type: "category", 5 | // label: "Intro", 6 | // items: ["doc1"], 7 | // }, 8 | // Docusaurus: ["doc1", "doc2", "doc3"], 9 | // Features: ["mdx"], 10 | // }, 11 | // }; 12 | 13 | module.exports = { 14 | docs: [ 15 | { 16 | type: "category", 17 | label: "Materi", 18 | items: ["intro", "component", "hook", "context", "stylecss", "patterns"], 19 | }, 20 | { 21 | type: "category", 22 | label: "Lanjutan", 23 | items: ["ref"], 24 | }, 25 | ], 26 | }; 27 | -------------------------------------------------------------------------------- /web/src/css/custom.css: -------------------------------------------------------------------------------- 1 | /* stylelint-disable docusaurus/copyright-header */ 2 | /** 3 | * Any CSS included here will be global. The classic template 4 | * bundles Infima by default. Infima is a CSS framework designed to 5 | * work well for content-centric websites. 6 | */ 7 | 8 | /* You can override the default Infima variables here. */ 9 | :root { 10 | --ifm-color-primary: #25c2a0; 11 | --ifm-color-primary-dark: rgb(33, 175, 144); 12 | --ifm-color-primary-darker: rgb(31, 165, 136); 13 | --ifm-color-primary-darkest: rgb(26, 136, 112); 14 | --ifm-color-primary-light: rgb(70, 203, 174); 15 | --ifm-color-primary-lighter: rgb(102, 212, 189); 16 | --ifm-color-primary-lightest: rgb(146, 224, 208); 17 | --ifm-code-font-size: 95%; 18 | } 19 | 20 | .docusaurus-highlight-code-line { 21 | background-color: rgb(72, 77, 91); 22 | display: block; 23 | margin: 0 calc(-1 * var(--ifm-pre-padding)); 24 | padding: 0 var(--ifm-pre-padding); 25 | } 26 | body { 27 | font-size: 1.1rem; 28 | /* font-style: normal; */ 29 | /* font-family: -apple-system, system-ui, BlinkMacSystemFont, 30 | 'Segoe UI', Roboto, 'Helvetica Neue', 31 | Ubuntu, Arial, sans-serif; */ 32 | font-family: -apple-system, BlinkMacSystemFont, “Segoe UI”, “Roboto”, “Oxygen”, 33 | “Ubuntu”, “Cantarell”, “Fira Sans”, “Droid Sans”, “Helvetica Neue”, 34 | sans-serif; 35 | } 36 | -------------------------------------------------------------------------------- /web/src/pages/styles.module.css: -------------------------------------------------------------------------------- 1 | /* stylelint-disable docusaurus/copyright-header */ 2 | 3 | /** 4 | * CSS files with the .module.css suffix will be treated as CSS modules 5 | * and scoped locally. 6 | */ 7 | 8 | .heroBanner { 9 | padding: 4rem 0; 10 | text-align: center; 11 | position: relative; 12 | overflow: hidden; 13 | } 14 | 15 | @media screen and (max-width: 966px) { 16 | .heroBanner { 17 | padding: 2rem; 18 | } 19 | } 20 | 21 | .buttons { 22 | display: flex; 23 | align-items: center; 24 | justify-content: center; 25 | } 26 | 27 | .features { 28 | display: flex; 29 | align-items: center; 30 | padding: 2rem 0; 31 | width: 100%; 32 | } 33 | 34 | .featureImage { 35 | height: 200px; 36 | width: 200px; 37 | } 38 | -------------------------------------------------------------------------------- /web/static/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SastraNababan/react-ts/44c81fa21432af21cb04172a09d311d57f3f10c7/web/static/.nojekyll -------------------------------------------------------------------------------- /web/static/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SastraNababan/react-ts/44c81fa21432af21cb04172a09d311d57f3f10c7/web/static/img/favicon.ico -------------------------------------------------------------------------------- /web/static/img/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/static/img/undraw_docusaurus_mountain.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /web/static/img/undraw_docusaurus_react.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /web/static/img/undraw_docusaurus_tree.svg: -------------------------------------------------------------------------------- 1 | docu_tree -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | rehype-truncate@^1.2.1: 6 | version "1.2.1" 7 | resolved "https://registry.yarnpkg.com/rehype-truncate/-/rehype-truncate-1.2.1.tgz#6614f4672f7067848b77b4a325c4446c7ab29666" 8 | integrity sha512-MEAA9gVx6LOKCCRELxuYd1h/pLQIzPW2fzFpe3rfNuFoJ40nx0RRBDEN3zVkusRJN1l0F9/85FRZMnVEGF3R1A== 9 | --------------------------------------------------------------------------------