Skip to content

Commit 6adfaa3

Browse files
committed
feat: add useScript hook
1 parent f37836f commit 6adfaa3

25 files changed

+3596
-2604
lines changed

.babelrc.cjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* eslint-env node, es2018 */
2+
module.exports = function (api) {
3+
const base = require('@jcoreio/toolchain-esnext/.babelrc.cjs')(api)
4+
return {
5+
...base,
6+
}
7+
}

.babelrc.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

.circleci/config.yml

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
1+
# created by @jcoreio/toolchain-circle
2+
13
version: 2.1
24
jobs:
35
build:
46
docker:
5-
- image: circleci/node:16
7+
- image: cimg/node:20.3.0
68

79
steps:
810
- checkout
911
- run:
1012
name: Setup NPM Token
1113
command: |
12-
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
13-
echo "registry=https://registry.npmjs.org/" >> ~/.npmrc
14-
# https://github.com/atlassian/react-beautiful-dnd/issues/1007#issuecomment-446415426
15-
- run:
16-
name: Workaround for Flow crashing
17-
command: echo "server.max_workers=1" >> .flowconfig
14+
npm config set \
15+
"//registry.npmjs.org/:_authToken=$NPM_TOKEN" \
16+
"registry=https://registry.npmjs.org/"
1817
- run:
19-
name: Install pnpm
20-
command: sudo npm install --global pnpm
18+
name: Corepack enable
19+
command: sudo corepack enable
2120
- run:
2221
name: Install Dependencies
2322
command: pnpm install --frozen-lockfile
2423
- run:
25-
name: build
26-
command: pnpm prepublishOnly
27-
- run:
28-
name: upload test coverage
29-
command: pnpm codecov
24+
name: Prepublish
25+
command: |
26+
[[ $(netstat -tnlp | grep -F 'circleci-agent') ]] || pnpm run tc prepublish
3027
- run:
31-
name: release
32-
command: pnpm semantic-release
28+
name: Release
29+
command: |
30+
[[ $(netstat -tnlp | grep -F 'circleci-agent') ]] || pnpm run tc release
31+
3332
workflows:
34-
build-and-deploy:
33+
build:
3534
jobs:
3635
- build:
3736
context:
38-
- github-release
3937
- npm-release
38+
- github-release

.eslintrc

Lines changed: 0 additions & 18 deletions
This file was deleted.

.eslintrc.cjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* eslint-env node, es2018 */
2+
module.exports = {
3+
extends: [require.resolve('@jcoreio/toolchain/eslint.config.cjs')],
4+
env: {
5+
es2017: true,
6+
},
7+
}

.flowconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<PROJECT_ROOT>/node_modules/fbjs/.*
88
<PROJECT_ROOT>/node_modules/.*/config-chain/.*
99
<PROJECT_ROOT>/node_modules/.*/resolve/.*
10+
<PROJECT_ROOT>/dist/.*
11+
.*/malformed_package_json/.*
1012

1113
[include]
1214
./src

.gitignore

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
/coverage
2-
/.nyc_output
1+
/dist
2+
.nyc_output
33
node_modules
4-
/lib
5-
/es
6-
.eslintcache
7-
*.js
8-
*.js.flow
9-
*.ts
10-
!/flow-typed/**/*.js
11-
!/src/**/*.js
12-
!/src/**/*.ts
13-
!/test/**/*.js
14-
!/.babelrc.js
15-
!/webpack.config.js
4+
/coverage

.mocharc.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-env node, es2018 */
2+
const base = require('@jcoreio/toolchain-mocha/.mocharc.cjs')
3+
module.exports = {
4+
...base,
5+
require: [...base.require, require.resolve('./test/configure.js')],
6+
}

.npmignore

Lines changed: 0 additions & 13 deletions
This file was deleted.

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[![npm version](https://badge.fury.io/js/react-library-skeleton.svg)](https://badge.fury.io/js/react-library-skeleton)
77

88
an easier to use dynamic script loader with a [render prop](https://reactjs.org/docs/render-props.html)
9+
and now a React custom hook.
910

1011
This is useful if you want to wait to load the Google Maps API until the user
1112
navigates to a view that uses it. When you mount a `<ScriptLoader>` component,
@@ -17,7 +18,6 @@ prop changes, it will load that new URL.
1718

1819
# Version notes
1920

20-
- supports React 15 or 16
2121
- if building for legacy browsers with a bundler like Webpack that supports the
2222
`module` field of `package.json`, you will probably need to add a rule to
2323
transpile this package.
@@ -56,6 +56,38 @@ export const MapViewContainer = (props) => (
5656

5757
# API
5858

59+
## `useScript(props: Props)`
60+
61+
```js
62+
import { useScript } from 'react-render-props-script-loader'
63+
```
64+
65+
### `props.src` (**required** `string`)
66+
67+
The script URL.
68+
69+
### `props.onLoad` (`?() => any`)
70+
71+
A callback that `ScriptLoader` will call once the script has been loaded
72+
73+
### `props.onError` (`?(error: Error) => any`)
74+
75+
A callback that `ScriptLoader` will call if there was an error loading the
76+
script
77+
78+
### Returns
79+
80+
A state object of the following type:
81+
82+
```ts
83+
type State = {
84+
loading: boolean
85+
loaded: boolean
86+
error: ?Error
87+
promise: ?Promise<any>
88+
}
89+
```
90+
5991
## `ScriptLoader`
6092
6193
```js

githooks.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* eslint-env node, es2018 */
2+
const base = require('@jcoreio/toolchain/githooks.cjs')
3+
module.exports = {
4+
...base,
5+
}

lint-staged.config.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* eslint-env node, es2018 */
2+
const base = require('@jcoreio/toolchain/lint-staged.config.cjs')
3+
module.exports = {
4+
...base,
5+
}

nyc.config.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* eslint-env node, es2018 */
2+
const base = require('@jcoreio/toolchain-mocha/nyc.config.cjs')
3+
module.exports = {
4+
...base,
5+
}

0 commit comments

Comments
 (0)