Skip to content

Commit 5bc13b9

Browse files
committed
chore(exampe): add typescript sample
1 parent 3703974 commit 5bc13b9

File tree

11 files changed

+1348
-3
lines changed

11 files changed

+1348
-3
lines changed

.babelrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
}
99
}
1010
],
11-
"@babel/preset-flow",
1211
"@babel/preset-react"
1312
]
1413
}

example/basic/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
22
"name": "basic",
33
"version": "1.0.0",
4-
"main": "index.js",
54
"license": "MIT",
65
"scripts": {
7-
"i18n": "NODE_ENV=development extract-messages -l=en,ja -o i18n -d en 'src/**/*.{js,tsx}'"
6+
"i18n": "NODE_ENV=development extract-messages -l=en,ja -o i18n -d en 'src/**/*.{js,jsx}'"
87
},
98
"dependencies": {
109
"react": "^16.13.1",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = function (api) {
2+
api.cache(true)
3+
4+
return {
5+
presets: ['@babel/preset-react', '@babel/preset-typescript']
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"App": {
3+
"hello": "Hello Button",
4+
"submit": "Submit Button"
5+
},
6+
"a": {
7+
"hello": "hello",
8+
"world": "world"
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"App": {
3+
"hello": "",
4+
"submit": ""
5+
},
6+
"a": {
7+
"hello": "",
8+
"world": ""
9+
}
10+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "with-typescript",
3+
"version": "1.0.0",
4+
"license": "MIT",
5+
"scripts": {
6+
"i18n": "extract-messages -l=en,ja -o i18n -d en 'src/**/*.{ts,tsx}'"
7+
},
8+
"dependencies": {
9+
"react": "^16.13.1",
10+
"react-intl": "^4.3.1"
11+
},
12+
"devDependencies": {
13+
"@babel/core": "^7.9.0",
14+
"@babel/preset-react": "^7.9.4",
15+
"@babel/preset-typescript": "^7.9.0",
16+
"extract-react-intl-messages": "latest",
17+
"typescript": "^3.8.3"
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react'
2+
import { injectIntl, useIntl } from 'react-intl'
3+
4+
export const SubmitButton = injectIntl(({ intl }) => {
5+
const label = intl.formatMessage({
6+
id: 'App.submit',
7+
defaultMessage: 'Submit Button'
8+
})
9+
return <button aria-label={label}>{label}</button>
10+
})
11+
12+
export const HelloButton = () => {
13+
const intl = useIntl()
14+
const label = intl.formatMessage({
15+
id: 'App.hello',
16+
defaultMessage: 'Hello Button'
17+
})
18+
return <button aria-label={label}>{label}</button>
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineMessages } from 'react-intl'
2+
3+
export default defineMessages({
4+
hello: {
5+
id: 'a.hello',
6+
defaultMessage: 'hello'
7+
},
8+
world: {
9+
id: 'a.world',
10+
defaultMessage: 'world'
11+
}
12+
})

0 commit comments

Comments
 (0)