Open IlyaSemenov opened 3 years ago
Issue-Label Bot is automatically applying the label feature_request
to this issue, with a confidence of 0.88. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!
Links: app homepage, dashboard and code for this bot.
@IlyaSemenov Hi, You are right. We want to rewrite this component with hooks. Thanks for your 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.