Skip to content
This repository was archived by the owner on Dec 31, 2020. It is now read-only.
This repository was archived by the owner on Dec 31, 2020. It is now read-only.

Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call) #656

@Hypothesis-github

Description

@Hypothesis-github

Introducing ' observer ' to the component results in triggering of the above error.

here is my code :

import React from 'react'
import { Form } from 'semantic-ui-react'
import {inject , observer} from 'mobx-react'

const Login = observer((props) => {
  
    const [username, setUsername] = React.useState(``)
    const [password, setPassword] = React.useState(``)

    
    const  handleSubmit = async () => {

        


        try {

            fetch('api/cockpit/authUser?token=xxxxx', {
            method: 'post',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({
                user: username,
                password
            })
        })
        .then(user => user.json()) 
        .then(user => {
            console.log(user.active)
            props.store.loggedMsg = user.active
        })
            
        } catch (error) {
            props.store.loggedMsg = error
        }
    }


    return (
        <>
            <Form onSubmit={handleSubmit}>
                <Form.Group>
                    <Form.Input placeholder='Username' value={username} onChange={(e) => setUsername(e.target.value)} />
                    <Form.Input
                        placeholder='Password'
                        type='password'
                        value={password}
                        onChange={(e) => setPassword(e.target.value)}
                    />
                    <Form.Button content='Submit' />
                </Form.Group>
            </Form>
           { console.log(props.store.loggedMsg)}
        </>
    )

})

export default inject('store') (Login)

Do I have to resort to mobx-lite?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions