zakodium-oss / react-science

React components and tools to build scientific applications.
https://react-science.pages.dev
MIT License
3 stars 6 forks source link

set a default selected item for the select component #680

Closed hamed-musallam closed 5 months ago

hamed-musallam commented 5 months ago

I propose some changes to the useSelect hook to provide more flexibility:

1 - The hook can accept a defaultSelectedItem property, so it is not restricted to use null as the default value.

https://github.com/zakodium-oss/react-science/blob/ca1af0eb1d0d727f1c0b0b6712e5afd72044f62e/src/components/hooks/useSelect.tsx#L6

2- Additionally, you can specify which object serves as the label, instead of assuming that the label object is always used. This allows for more customization and avoids the need to remap the list.

https://github.com/zakodium-oss/react-science/blob/ca1af0eb1d0d727f1c0b0b6712e5afd72044f62e/src/components/hooks/useSelect.tsx#L26

https://github.com/zakodium-oss/react-science/blob/ca1af0eb1d0d727f1c0b0b6712e5afd72044f62e/src/components/hooks/useSelect.tsx#L26

https://github.com/zakodium-oss/react-science/blob/ca1af0eb1d0d727f1c0b0b6712e5afd72044f62e/src/components/hooks/useSelect.tsx#L49

stropitek commented 5 months ago

The hook can accept a defaultSelectedItem property, so it is not restricted to use null as the default value.

SGTM

Additionally, you can specify which object serves as the label, instead of assuming that the label object is always used. This allows for more customization and avoids the need to remap the list.

I think that to allow this, the hook should be more generic and accept any type of shape for option. A custom render function can be passed which takes the option and can do any logic it wants on it.