-
Notifications
You must be signed in to change notification settings - Fork 57
Description
Most React components that deal with user input accept callbacks returned by React.useState, for instance:
import { TextInput } from "react-native"
...
export const MyComponent = () => {
const [value, setValue] = React.useState("")
return <TextInput value={value} onChangeText={setValue} />
}
This is however not the case with your component's onSelected
. One has to write boilerplate like:
<PickerModal onSelected={(object) => {
setValue("" + object.Id) // object.Id is not text but React.ReactText?? one more weirdness.
return object
}} />
This API is awkward and not following React best practices. There's no point in returning anything. Like: why would you want to pass a (possibly updated) object
further? If you need it for renderSelectView
, then there is already prop selected
for that. Normally, in React, it's up to onSelected
to update (or don't update) some external variable which is then passed to selected
as a prop. Your component should not be managing the state itself.
Please consider updating the API to how literally every other similar component works. At the very least, allow callbacks to return nothing (undefined) because currently it's not the case.