How to use relative file module with Create React app
Issue #751
Declare data/package.json
to make it into node module
1 | { |
Then in landing/package.json
, use file
1 | { |
Issue #751
Declare data/package.json
to make it into node module
1 | { |
Then in landing/package.json
, use file
1 | { |
Issue #705
Supposed we have date in format ISO8601 and we want to get rid of T and millisecond and timezone Z
1 | const date = new Date() |
We can use toISOString
, then split base on the dot .
then remove character T
1 | date |
Issue #699
Use term ZStack
like in SwiftUI, we declare container as relative position. For now it uses only 2 items from props.children
but can be tweaked to support mutiple
1 | class App extends React.Component { |
1 | /** @jsx jsx */ |
Updated at 2021-01-15 22:03:49
Issue #669
Specify params as array [year, id]
, not object {year, id}
1 | const { year, id } = props |
By default, it runs both after the first render and after every update.
This requirement is common enough that it is built into the useEffect Hook API. You can tell React to skip applying an effect if certain values haven’t changed between re-renders. To do so, pass an array as an optional second argument to useEffect:
1 | useEffect(() => { |
Updated at 2020-06-17 06:21:08
Issue #664
Use moment-timezone https://momentjs.com/timezone/docs/
1 | npm install moment-timezone |
Need to import from moment-timezone
, not moment
1 | import moment from 'moment-timezone' |
Issue #661
Use Bulma css
1 | <input |
Updated at 2020-06-16 07:30:52
Issue #661
Use Bulma css
1 | <input |
Issue #659
Use useLocation
https://reacttraining.com/react-router/web/guides/scroll-restoration
1 | import React, { useEffect } from 'react'; |
Updated at 2020-06-04 05:58:47
Issue #658
Declare routes, use exact
to match exact path as finding route is from top to bottom. For dynamic route, I find that we need to use render and pass the props manually.
Declare Router
as the rooter with Header, Content and Footer. Inside Content there is the Switch
, so header and footer stay the same across pages
1 | import { |
To trigger route request, use useHistory
hook. Note that we need to declare variable, and not use useHistory().push
directly
1 | import { useHistory } from 'react-router-dom' |
To get parameters, use match
1 | export default function BookDetail(props) { |
Updated at 2020-06-03 05:07:00
Issue #657
Add library folder src/library
1 | src |
Declare package.json in library
folder
1 | { |
Declare library as dependency in root package.json
1 | "dependencies": { |
Now import like normal, for example in src/screens/Home/index.js
1 | import res from 'library/res' |
Issue #648
In a similar fashion to plain old javascript, note that href
needs to have valid hash tag, like #features
1 | <a |
Updated at 2020-05-06 08:36:21
Issue #643
Use material icons
1 | <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> |
1 | div#filter-container { |
1 | filters.forEach((filter) => { |
Updated at 2020-04-27 22:03:13
Issue #641
Create a new page
1 | hexo new page mydemo |
Remove index.md
and create index.html
, you can reference external css and js in this index.html
. Hexo has hexo new page mydemo --slug
but it does not support page hierarchy
Specify no layout so it is independent page.
1 | --- |
Issue #640
1 | async function useCache( |
1 | useCache( |
Issue #552
1 | type Components = { |
Issue #492
Suppose we have a base Localizable.strings
1 | "open" = "Open"; |
After sending that file for translations, we get translated versions.
1 | "open" = "Åpen"; |
Searching and copy pasting these to our Localizable.strings is tedious and time consuming. We can write a script to apply that.
Remember that we need to be aware of smart and dump quotes
1 | .replace(/\"/g, '') |
1 | const fs = require('fs') |
Issue #476
React Native comes with a default React library, and most CocoaPods libraries for React Native has React as a dependency pod, which causes the conflict
Issue #430
1 | npm install electron-builder@latest --save-dev |
package.json
1 | { |
entitlements.plist
1 |
|
afterSignHook.js
1 | const fs = require('fs'); |
Generate password for Apple Id because of 2FA
1 | export appleId=onmyway133@gmail.com |
1 | spctl --assess --verbose Icon\ Generator.app |
dist
folder for distribution, for example dist/mac/Icon Generator
, I’ve renamed babel generated code to babel
directoryIt is because of afterSignHook. Ignore in .babelrc
not work
1 | { |
Should use babel 7 with babel.config.js
1 | npm install --save @babel/runtime |
https://httptoolkit.tech/blog/notarizing-electron-apps-with-electron-forge/
Issue #423
Add 4 A records
1 | A @ 185.199.110.153 |
and 1 CNAME record
1 | CNAME www learntalks.github.io |
learntalks.com
public/CNAME
1 | learntalks.com |
Issue #420
1 | const normalized = string |
Issue #419
1 | function write(json) { |
1 | async function readAll() { |
Issue #418
Path for user users/nsspain/videos
Path for showcase https://developer.vimeo.com/api/reference/albums#get_album
Path for Channels, Groups and Portfolios
1 | const Vimeo = require('vimeo').Vimeo |
Response look like
1 | { |
Issue #417
1 | class Youtube { |
Response look like
1 | { |
To handle pagination
1 | async getVideosLoop(playlistId, nextPageToken, items, count) { |
To get playlist title, use playlists.list
Issue #416
1 | // @flow |
1 | const videos = await toPromise(callback) |
If a function accepts many parameters, we need to curry https://onmyway133.github.io/blog/Curry-in-Swift-and-Javascript/
1 | function curry2(f) { |
Issue #415
https://stackoverflow.com/questions/44391448/electron-require-is-not-defined
1 | function createWindow () { |
1 | npm install babel-cli@latest --save-dev |
1 | win.openDevTools() |
This leads to Cannot find module 'react/lib/ReactComponentTreeHook'
If we’re using binary, then rebuild, it is the problem that cause devTools not work
1 | npx electron-builder |
This goes to Cannot read property injection of undefined at react-tap-event-plugin
https://github.com/zilverline/react-tap-event-plugin/issues/121
1 | npm uninstall react-tap-event-plugin |
This goes to Unknown event handler property onTouchTap
in EnhancedButton in material-ui
https://material-ui.com/
https://material-ui.com/guides/migration-v0x/#raised-button
1 | npm install @material-ui/core |
From
1 | import RadioButtonGroup from '@material-ui/core/RadioButton/RadioButtonGroup' |
to
1 | import RadioButtonGroup from '@material-ui/core/RadioGroup' |
Use FormControlLabel https://material-ui.com/components/radio-buttons/
1 | <RadioGroup |
Issue #400
Issue #399
App.js
1 | import React, { Component } from 'react'; |
Main.js
1 | // @flow |
Use express
and socket.io
index.js
1 | // @flow |
Issue #398
Dependencies
1 | const Rx = require('rxjs/Rx') |
Use GraphQL
1 | makeOptions(query, token) { |
Use orderBy
1 | fetchPRsAndIssues(dates) { |
Issue #393
https://developer.github.com/v4/explorer/
1 | query { |
In node.js
1 | const GraphQL = require('graphql-request') |
Issue #392
It’s been a long journey since https://github.com/onmyway133/blog/issues/1, next step is to keep GitHub issues as source, and mirror those to a static site.
Use 2 repos
1 | npm install -g hexo-cli |
Update _config.yml
1 | deploy: |
1 | hexo clean |