diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000..51c5f3f --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,39 @@ +/* eslint-env node */ +module.exports = { + root: true, + parser: '@typescript-eslint/parser', + plugins: ['@typescript-eslint'], + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:import/recommended', + 'plugin:import/typescript', + 'plugin:react/recommended', + 'plugin:react/jsx-runtime', + 'plugin:react-hooks/recommended', + 'plugin:jsx-a11y/recommended', + 'prettier', + ], + ignorePatterns: ['dist/'], + settings: { + 'import/resolver': { + typescript: true, + }, + react: { version: 'detect' }, + }, + rules: { + 'import/no-unresolved': ['error', { ignore: ['use-context-selector'] }], + '@typescript-eslint/no-unused-vars': [ + 'error', + { + args: 'all', + argsIgnorePattern: '^_', + caughtErrors: 'all', + caughtErrorsIgnorePattern: '^_', + destructuredArrayIgnorePattern: '^_', + varsIgnorePattern: '^_', + ignoreRestSiblings: true, + }, + ], + }, +}; diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index dc3fabe..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "parser": "@typescript-eslint/parser", - "plugins": [ - "@typescript-eslint", - "react-hooks" - ], - "extends": [ - "plugin:@typescript-eslint/recommended", - "airbnb" - ], - "env": { - "browser": true - }, - "settings": { - "import/resolver": { - "node": { - "extensions": [".js", ".ts", ".tsx"] - } - } - }, - "rules": { - "react-hooks/rules-of-hooks": "error", - "react-hooks/exhaustive-deps": ["error", { "additionalHooks": "useIsomorphicLayoutEffect" }], - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/explicit-module-boundary-types": "off", - "@typescript-eslint/no-explicit-any": "off", - "react/jsx-filename-extension": ["error", { "extensions": [".js", ".tsx"] }], - "react/prop-types": "off", - "react/jsx-one-expression-per-line": "off", - "import/extensions": ["error", "never"], - "import/no-unresolved": ["error", { "ignore": ["use-context-selector"] }], - "symbol-description": "off", - "no-use-before-define": "off", - "no-unused-vars": "off", - "react/function-component-definition": ["error", { "namedComponents": "arrow-function" }] - }, - "overrides": [{ - "files": ["__tests__/**/*"], - "env": { - "jest": true - }, - "rules": { - "import/no-extraneous-dependencies": ["error", { "devDependencies": true }] - } - }] -} diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..545d736 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +/pnpm-lock.yaml +/dist +/README.md diff --git a/CHANGELOG.md b/CHANGELOG.md index e104f66..ddbe875 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,171 +2,258 @@ ## [Unreleased] +### Changed + +- Module-first setup #125 + ### Removed -- Breaking: drop react < 18 support + +- Breaking: drop react < 18 support #124 ## [1.4.4] - 2024-03-08 + ### Changed + - fix(react-native): metro without exports support #118 ## [1.4.3] - 2024-03-06 + ### Changed + - fix: react-native entry point #116 ## [1.4.2] - 2024-03-02 + ### Changed + - fix: unimplemented scheduler like RN #114 ## [1.4.1] - 2022-06-07 + ### Changed + - fix(build): build script for React Native #83 ## [1.4.0] - 2022-05-17 + ### Added + - experimental suspense/transition support #80 ## [1.3.10] - 2022-04-12 + ### Changed + - Fix types for @types/react@18 (#75) ## [1.3.9] - 2021-09-20 + ### Changed + - Fix build config (obsoleting v1.3.8 which isn't built correctly) ## [1.3.8] - 2021-09-18 + ### Changed + - Fix package.json properly for ESM - Refactor version check with triple equal (#54) ## [1.3.7] - 2021-01-24 + ### Changed + - Fix extra commits introduced in v1.3.6 (#39) ## [1.3.6] - 2021-01-23 + ### Changed + - Fix cases rendered from parent (#38) ## [1.3.5] - 2021-01-06 + ### Changed + - More strict type for useContextUpdate return value + ### Added + - Preact support with scheduler=false (#36) ## [1.3.4] - 2020-12-12 + ### Changed + - Refactor useBridgeValue because it does not depend on changedBits=0 ## [1.3.3] - 2020-12-11 + ### Changed + - Fix an edge case with render bail out (with useContextUpdate) ## [1.3.2] - 2020-12-03 + ### Changed + - Fix useBridgeValue typing ## [1.3.1] - 2020-12-03 + ### Changed + - Refactor for efficiency and bundle size - Check typeof process for `NODE_ENV` ## [1.3.0] - 2020-12-01 + ### Changed + - No longer depends on changedBits=0 behavior - Tearing with parent can't be avoided - Migrate to TypeScript ## [1.2.12] - 2020-11-29 + ### Changed + - Re-implement without latest ref for value/selected to fix edge cases ## [1.2.11] - 2020-11-09 + ### Changed + - Fix default context value ## [1.2.10] - 2020-10-17 + ### Added + - Peer dependencies for React Native ## [1.2.9] - 2020-10-16 + ### Changed + - Fix compile script for ESM build ## [1.2.8] - 2020-10-08 + ### Changed + - Fix incomplete useBridgeValue implementation ## [1.2.7] - 2020-10-08 + ### Changed + - Fix missing useBridgeValue type ## [1.2.6] - 2020-10-08 + ### Added + - useBridgeValue for BridgeProvider ## [1.2.5] - 2020-10-03 + ### Changed + - Again fix bundle for React Native (#27) ## [1.2.4] - 2020-10-03 + ### Changed + - Fix bundle for React Native (#26) ## [1.2.3] - 2020-10-03 + ### Changed + - Fix back porting bug in v1.2.0-v1.2.2 ## [1.2.2] - 2020-10-02 + ### Added + - useIsomorphicLayoutEffect for SSR (#25) ## [1.2.1] - 2020-10-01 + ### Added + - Type definition for useContextUpdate ## [1.2.0] - 2020-10-01 + ### Added + - useContextUpdate for state branching support ## [1.1.4] - 2020-09-22 + ### Added + - BridgeProvider for multiple react roots ## [1.1.3] - 2020-09-17 + ### Changed + - useIsoLayoutEffect for SSR ## [1.1.2] - 2020-07-02 + ### Changed + - Modern build ## [1.1.1] - 2020-03-02 + ### Changed + - Avoid React render warning in test (#15) ## [1.1.0] - 2020-02-24 + ### Changed + - A workaround for React render warning (#13) ## [1.0.1] - 2019-09-27 + ### Changed + - Shave more bytes in the production environment (#6) ## [1.0.0] - 2019-08-02 + ### Changed + - Fix API v1 ## [0.4.0] - 2019-07-23 + ### Changed + - Shave bytes (#2) ## [0.3.0] - 2019-07-20 + ### Changed + - No useLayoutEffect for invoking listeners (which leads de-opt sync mode) ## [0.2.0] - 2019-07-07 + ### Changed + - Use microbundle ## [0.1.0] - 2019-07-05 + ### Added + - Initial release diff --git a/README.md b/README.md index 6be2191..066b99a 100644 --- a/README.md +++ b/README.md @@ -48,40 +48,46 @@ Its usage is optional and only required if the default behavior is unexpected. ## Usage ```javascript -import React, { useState } from 'react'; -import ReactDOM from 'react-dom'; +import { useState } from 'react'; +import { createRoot } from 'react-dom/client'; import { createContext, useContextSelector } from 'use-context-selector'; const context = createContext(null); const Counter1 = () => { - const count1 = useContextSelector(context, v => v[0].count1); - const setState = useContextSelector(context, v => v[1]); - const increment = () => setState(s => ({ - ...s, - count1: s.count1 + 1, - })); + const count1 = useContextSelector(context, (v) => v[0].count1); + const setState = useContextSelector(context, (v) => v[1]); + const increment = () => + setState((s) => ({ + ...s, + count1: s.count1 + 1, + })); return (