Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use renderSuggestions as React component rather than calling directly #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lafiosca
Copy link

@lafiosca lafiosca commented Mar 24, 2021

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
Copy link
Author

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.

@GabrielModog
Copy link

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

@nanhlua96
Copy link

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

@GabrielModog
Copy link

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.

@lafiosca
Copy link
Author

lafiosca commented May 18, 2021

@GabrielModog The maintainer implied that this functionality might be in the next major release here: #44 (comment)

@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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants