feat: @avocado/react
This commit is contained in:
parent
3385daf8d8
commit
d6bb894f49
7
packages/react/.gitignore
vendored
Normal file
7
packages/react/.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
**/*.js
|
||||
**/*.map
|
||||
!/.*
|
||||
!/postcss.config.js
|
||||
!/webpack.config.js
|
||||
!src/**/*.js
|
||||
!/test/**/*.js
|
25
packages/react/package.json
Normal file
25
packages/react/package.json
Normal file
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "latus-build",
|
||||
"clean": "latus-build clean",
|
||||
"fp": "latus-build forcepublish",
|
||||
"lint": "latus-build lint",
|
||||
"test": "latus-build test"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.js.map",
|
||||
"test.js",
|
||||
"test.js.map"
|
||||
],
|
||||
"dependencies": {
|
||||
"@latus/core": "^2.0.0",
|
||||
"@latus/react": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@latus/build": "1.x"
|
||||
},
|
||||
"name": "@avocado/react"
|
||||
}
|
14
packages/react/src/hooks/use-property-change.js
Normal file
14
packages/react/src/hooks/use-property-change.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import {useCallback, useEvent, useState} from '@latus/react';
|
||||
|
||||
export default function usePropertyChange(object, property, defaultValue) {
|
||||
const [value, setValue] = useState(defaultValue);
|
||||
useEvent(
|
||||
object,
|
||||
`${property}Changed`,
|
||||
useCallback(() => {
|
||||
const newValue = object[property];
|
||||
setValue(newValue);
|
||||
}, [object, property]),
|
||||
);
|
||||
return value;
|
||||
}
|
2
packages/react/src/index.js
Normal file
2
packages/react/src/index.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
// eslint-disable-next-line import/prefer-default-export
|
||||
export {default as usePropertyChange} from './hooks/use-property-change';
|
5
packages/react/test/exists.js
Normal file
5
packages/react/test/exists.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
import {expect} from 'chai';
|
||||
|
||||
it('exists', () => {
|
||||
expect(true).to.be.true;
|
||||
});
|
6892
packages/react/yarn.lock
Normal file
6892
packages/react/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user