You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is however not the case with your component's onSelected. One has to write boilerplate like:
<PickerModalonSelected={(object)=>{setValue(""+object.Id)// object.Id is not text but React.ReactText?? one more weirdness.returnobject}}/>
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.
The text was updated successfully, but these errors were encountered:
Issue-Label Bot is automatically applying the label feature_request to this issue, with a confidence of 0.88. Please mark this comment with 👍 or 👎 to give our bot feedback!
Just to make it clear, the component doesn't necessary have to be rewritten with hooks. It works just fine as a class component. The problem is different: the component apparently stores the internal state (what has been selected), and updates it with the result of onSelected callback. Instead, it should simply use selected property for the current state, so that the state is managed by external code (not the component).
Of course it means breaking the API, so if you decide to follow this road that could land in a next major release.
Most React components that deal with user input accept callbacks returned by React.useState, for instance:
This is however not the case with your component's
onSelected
. One has to write boilerplate like: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 forrenderSelectView
, then there is already propselected
for that. Normally, in React, it's up toonSelected
to update (or don't update) some external variable which is then passed toselected
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.
The text was updated successfully, but these errors were encountered: