Repository navigation
refactor(useBooleanState, useStorageState, useCounter): return the value with an actions object - #532
Conversation
🦋 Changeset detectedLatest commit: a403c7e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Size Change: +266 B (+0.23%) Total Size: 115 kB 📦 View Changed
ℹ️ View Unchanged
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v1-base #532 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 69 69
Lines 2280 2281 +1
Branches 735 738 +3
=========================================
+ Hits 2280 2281 +1 🚀 New features to boost your workflow:
|
// before
const [value, setTrue, setFalse, toggle] = useBooleanState(false);
const [value, setValue, refresh] = useStorageState<string>('token');
const [list, { push, insertAt, updateAt, removeAt, setAll, reset }] = useList<string>(['a', 'b']);
const [map, { set, setAll, remove, reset }] = useMap<string, number>([['a', 1]]);
const [set, { add, remove, toggle, setAll, reset }] = useSet<string>(['a']);
// after (this pr now)
const { value, setTrue, setFalse, toggle } = useBooleanState(false);
const { value, setValue, refresh } = useStorageState<string>('token');
const { list, push, insertAt, updateAt, removeAt, setAll, reset } = useList<string>(['a', 'b']);
const { map, set, setAll, remove, reset } = useMap<string, number>([['a', 1]]);
const { set, add, remove, toggle, setAll, reset } = useSet<string>(['a']);
// or this ???
const [isOpen, { setTrue, setFalse, toggle }] = useBooleanState(false);
const [token, { setValue, refresh }] = useStorageState<string>('token');
const [list, { push, insertAt, updateAt, removeAt, setAll, reset }] = useList<string>(['a', 'b']); // same as before
const [map, { set, setAll, remove, reset }] = useMap<string, number>([['a', 1]]); // same as before
const [set, { add, remove, toggle, setAll, reset }] = useSet<string>(['a']); // same as before |
…lue with an actions object
17f6d47 to
1425afb
Compare
…ing "hook" and translate the zh-Hans example comment
… tree-shaking size gate
|
@hyesungoh Went with const [isOpen, { setTrue, setFalse, toggle }] = useBooleanState(false);
const [token, { setValue, refresh }] = useStorageState<string>('token');
const [count, { increment, decrement, reset, setCount }] = useCounter(0);
|
hyesungoh
left a comment
There was a problem hiding this comment.
useCounter looks good to me! 👍
Not sure about deprecating useToggle though 🤔 Let's leave it as is for now and talk about it later.
Overview
useBooleanState,useStorageStateanduseCounternow return[value, actions], the same shapeuseList,useMapanduseSetalready use. Closes #528.This replaces the first draft, which returned a flat object. With a tuple, callers name the value per call site, and two
useBooleanStatecalls in one component no longer collide onsetTrue/toggle. Most libraries that ship a multi-action boolean hook use the same shape: ahooksuseBoolean, mantineuseDisclosure, chakra v2useBoolean.useTogglekeeps[value, toggle]and now declares its return type, so React 18 consumers no longer see the React 19ActionDispatchtype. Deprecating it in favor ofuseBooleanStatewill follow once the deprecated-export tooling lands.[value, action], two or more →[value, { actions }].yarn test,yarn test:coverage,yarn test:compiled,yarn test:docsandyarn test:skillpass.Checklist
yarn run fixto format and lint the code and docs?yarn run test:coverageto make sure there is no uncovered line?