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

Wrong message for anonymous functions #29

Open
ruiconti opened this issue Jan 17, 2022 · 2 comments · May be fixed by #30
Open

Wrong message for anonymous functions #29

ruiconti opened this issue Jan 17, 2022 · 2 comments · May be fixed by #30

Comments

@ruiconti
Copy link
Contributor

ruiconti commented Jan 17, 2022

Consider the following scenario:

const Component = observer(function (props: IProps)) { /* Note that this is, in fact, an anonymous function */
    const { useHook } = props;
    const { myState } = useHook(); /* A hook cannot be used inside of another function */
    return <div>{myState}</div>
})

const WrappedComponent = function() {
    const [state, setState] = React.useState();
    React.useEffect((
        expensiveState.lazyImport().then(s => setState(s));
    ), []);
    
    const Wrapper = React.useCallback(() => state ? <Component {...state}>/> : <Loading/>, [state])
    return <Wrapper/>
}

ReactDOM.render(<WrappedComponent />, ...)

It is in fact a wrong function React component declaration, as React component functions must be named. However, I'm arguing that we should provide a meaningful and relevant error message, analogous to the eslint plugin's.

@Gelio
Copy link
Owner

Gelio commented Jan 18, 2022

Hey! Thanks for the report. That's an excellent idea to improve the error message.

At the moment I am a bit busy with my thesis. I don't think I will have time to get it done within the next month. If you'd like, you could submit a pull request improving the error message with that case. If not, I should be able to take care of it by the end of February

Thanks again for the suggestion!

@ruiconti ruiconti linked a pull request Feb 2, 2022 that will close this issue
@ruiconti
Copy link
Contributor Author

ruiconti commented Feb 2, 2022

Thanks for the kind and thoughtful reply, @Gelio. I took a stab at it on #30.

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 a pull request may close this issue.

2 participants