Conversation
src/base/picker/Picker.tsx
Outdated
| touching: touching.value, | ||
| }); | ||
|
|
||
| const onTouchStart = useCallback(() => { |
There was a problem hiding this comment.
I assume that in this part (and the functions below) the useStableCallback hook would be more suitable, because we can always return the same function reference for callback events, which will prevent unnecessary re-renders. Additionally, this will simplify the code.
src/base/picker/Picker.tsx
Outdated
|
|
||
| const onTouchStart = useCallback(() => { | ||
| touching.setTrue(); | ||
| restProps.onTouchStart?.(); |
There was a problem hiding this comment.
For onTouchStart and other new events from props, declare them in the same way as for onValueChanging. That is...
onValueChanged,
onValueChanging,
onTouchStart,
...If a naming conflict arises, you can add the Prop suffix, for example:
{
...
onScrollEnd: onScrollEndProp,
...
}: ...This all relates to the destructuring of props.
There was a problem hiding this comment.
@neizerth
Sorry for not providing a good example of what I meant regarding Prop. This postfix needs to be added to variables (if there is a naming conflict) that are extracted from the props variable of a component. A good example is withScrollEndEvent.
src/base/picker/Picker.tsx
Outdated
| const onTouchStart = useCallback(() => { | ||
| touching.setTrue(); | ||
| restProps.onTouchStart?.(); | ||
| }, [touching, restProps]); |
There was a problem hiding this comment.
I want to point out that when you pass restProps into dependencies, it will always have a new reference during the parent component's re-render. This will result in a new function reference, leading to further re-renders of child components.
As one option for the future: instead of directly passing restProps, you could use restProps?.onTouchStart. This would also solve the problem.
Please be careful with this next time.)
Hi Sergey!
Thank you for your awesome project!
Added 4 list events:
onTouchStart?: () => void;
onTouchEnd?: () => void;
onTouchCancel?: () => void;
onScrollEnd?: () => void;
I need these props to make possible this behavior: show other values except selected only when touching is enabled
Have a nice day!