Skip to content

Allow onSelected to accept React.useState callbacks #68

@IlyaSemenov

Description

@IlyaSemenov

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions