react-native-controlled-mentions icon indicating copy to clipboard operation
react-native-controlled-mentions copied to clipboard

Use renderSuggestions as React component rather than calling directly

Open lafiosca opened this issue 3 years ago • 5 comments

Regarding #44, this patch slightly changes the return type of renderSuggestions and renders it as a React element rather than populating a fragment with its output. This is a subtle distinction but allows the function component passed as renderSuggestions to be hooks-based without having to wrap it in a (props) => ( <MentionSuggestions {...props} /> ) anonymous function.

I will understand if you do not want to incorporate this, as it is potentially a breaking change for people who are returning less typical ReactNode values from their renderSuggestions functions.

lafiosca avatar Mar 24 '21 19:03 lafiosca

Thinking about it more, it might make sense to change the parameter name to something that makes it clearer that it's a component if you decide to take this approach.

lafiosca avatar Mar 24 '21 19:03 lafiosca

This change will help a lot. No one to review?

GabrielModog avatar May 02 '21 02:05 GabrielModog

React node include null inside, return null not is feasible in the current code. You don't need change it.

nanhlua96 avatar May 18 '21 03:05 nanhlua96

But the way the code was wrote the never will reach the null value and this changes make it possible.

Because the comparison of props if is not a true value will return false, even if the ReactNode return null.

GabrielModog avatar May 18 '21 12:05 GabrielModog

@GabrielModog The maintainer implied that this functionality might be in the next major release here: https://github.com/dabakovich/react-native-controlled-mentions/issues/44#issuecomment-808016858

@nanhlua96 The type definition for ReactNode includes null, but it also includes a lot of other stuff. It doesn't match the return type of a function component, hence the proposed change:

type ReactNode = ReactChild | ReactFragment | ReactPortal | boolean | null | undefined;

interface FunctionComponent<P = {}> {
    (props: PropsWithChildren<P>, context?: any): ReactElement<any, any> | null;
    propTypes?: WeakValidationMap<P>;
    contextTypes?: ValidationMap<any>;
    defaultProps?: Partial<P>;
    displayName?: string;
}

lafiosca avatar May 18 '21 15:05 lafiosca