Releases: LauraBeatris/use-selected-items-hook
3.1.12
New Major Release
Break Changes
- Removed generic type for item identifier - It's being accessed with the
keyof
operator and there's no need to provide it manually #21 selectedItems
aren't returned with theisSelected
state #20- Type Definitions Updates (#21)
- toggleSingleItem action now receives the
item
as an argument
Improvements
2.1.10
New major release 🎉
But here comes the breaking changes...
New actions
The hook now returns two different actions in order to manipulate the items
state:
toggleSingleItem
toggleAllItems
Update return values
selectedItems
: The items that are currently selected.items
: The items with the status ofisSelected
.
export interface HookReturnValues<T> {
items: Item<T>[];
selectedItems: Item<T>[];
toggleAllItems: () => void;
toggleSingleItem: (itemIdentifierValue: any) => void;
}
Initialization
It's possible to initialize the isSelected
status of items
based on the initialSelectedItems
argument.
const noop = () => {};
const fetchItemsFromAPI = () => {..};
const Example = () => {
const [initialItems, setInitialItems] = useState([]);
useEffect(() => {
fetchItemsFromAPI()
.then(res => setInitialItems(res.data))
.catch(noop);
}, []);
const {
items,
selectedItems,
} = useSelectedItems({
itemIdentifierKey: "id",
initialItems: items,
initialSelectedItems: initialItems.filter(item => item.someRandomCondition);
});
}
1.1.9
New minor version #9
Bug Fix 🐛
The package was previously being bundled with react
, resulting in two different instances of React on the same components tree. #4
Improved workflows and project structure
-
Now all the configuration related to
rollup
andbabel
is being handled by https://github.com/formium/tsdx, which removed a lot of boilerplate in order to configurerollup
. -
husky
andlint-staged
are now in the root of the project, instead of being duplicated on theexample
app folder -
Added a better CI workflow which tests the package on multiple environments.
1.0.9
The hook module was being exported in the wrong way and leading to errors when trying to import the definitions of the types of the package.
Now, it should be imported as the following example:
import useSelectedItems from "use-selected-items-hook";
import { Item } from "use-selected-items-hook/build/types";
1.0.8
Misc
New patch release providing access to the definitions of the types of the package
import { Actions, HookArguments, Item, HookReturnValues } from "use-selected-items-hook"
1.0.7
1.0.5
Misc
- Updated dependencies and fixed module resolution