Package Exports
- @rooks/use-select
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rooks/use-select) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@rooks/use-select
About
Select values from a list easily. List selection hook for react.
Installation
npm install --save @rooks/use-select
Importing the hook
import useSelect from "@rooks/use-select"
Usage
const list = [
{
heading: "Tab 1",
content: "Tab 1 Content"
},
{
heading: "Tab 2",
content: "Tab 2 Content"
}
];
function Demo() {
const { index, setIndex, item } = useSelect(list, 0);
return (
<div>
{list.map((listItem, listItemIndex) => (
<button
key={listItemIndex}
style={{
background: index === listItemIndex ? "dodgerblue" : "inherit"
}}
onClick={() => setIndex(listItemIndex)}
>
{listItem.heading}
</button>
))}
<p>{item.content}</p>
</div>
);
}
render(<Demo/>)
Arguments
Argument | Type | Description | Default value |
---|---|---|---|
list | Array | List of items for which the selection is used | undefined |
initialIndex | number | Initially selected index | 0 |
Returned Object
Returned object attributes | Type | Description |
---|---|---|
index | int | Index of currently selected index |
item | any | Currently selected item |
setIndex | function | Update selected index |
setItem | function | Update selected item |