skip to Main Content

I prepared a login page in my project. Normally, I edited it with bootstrap and it was working.

But when I edit and save with ant desing, it gives an error. This is the error message:

"Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the rendering method of LoginForm.

It works in the old version, but I have this problem in the new version. I am sharing the code. Can you help me?

import React, { useState } from 'react';
import { Form, Button, Card, Tabs, Input } from 'antd';
import { UserOutlined, MailOutlined, LockOutlined } from '@ant-design/icons';

const { TabPane } = Tabs;

const LoginForm = () => {
  const [activeTab, setActiveTab] = useState('login');

  const handleTabChange = key => {
    setActiveTab(key);
  };

  return (
    <div className="d-flex justify-content-center align-items-center mt-5">
      <Card style={{ width: '400px' }}>
        <Card.Body>
          <Tabs
            activeKey={activeTab}
            onSelect={handleTabChange}
            className="mb-3"
          >
            <TabPane tab="Login" key="login">
              <Form>
                <Form.Item
                  label="Email"
                  name="loginEmail"
                  rules={[{ required: true, message: 'Lütfen email adresinizi girin!' }]}
                >
                  <Input prefix={<MailOutlined />} />
                </Form.Item>

                <Form.Item
                  label="Şifre"
                  name="loginPassword"
                  rules={[{ required: true, message: 'Lütfen şifrenizi girin!' }]}
                >
                  <Input.Password prefix={<LockOutlined />} />
                </Form.Item>

                <Form.Item>
                  <Button type="primary" htmlType="submit">
                    Giriş Yap
                  </Button>
                </Form.Item>
              </Form>
            </TabPane>

            <TabPane tab="Register" key="register">
              <Form>
                <Form.Item
                  label="Ad"
                  name="registerName"
                  rules={[{ required: true, message: 'Lütfen adınızı girin!' }]}
                >
                  <Input prefix={<UserOutlined />} />
                </Form.Item>

                <Form.Item
                  label="Email"
                  name="registerEmail"
                  rules={[{ required: true, message: 'Lütfen email adresinizi girin!' }]}
                >
                  <Input prefix={<MailOutlined />} />
                </Form.Item>

                <Form.Item
                  label="Şifre"
                  name="registerPassword"
                  rules={[{ required: true, message: 'Lütfen şifrenizi girin!' }]}
                >
                  <Input.Password prefix={<LockOutlined />} />
                </Form.Item>

                <Form.Item>
                  <Button type="primary" htmlType="submit">
                    Kayıt Ol
                  </Button>
                </Form.Item>
              </Form>
            </TabPane>
          </Tabs>
        </Card.Body>
      </Card>
    </div>
  );
};

export default LoginForm;

solve to login form import problem

3

Answers


  1. From what I can see, Antd is no longer support TabPane, so that might be the cause of your problem.

    Maybe this thread can help you to fix the problem: https://github.com/ant-design/ant-design/issues/42021

    Or just see some examples from Antd’s official docs of how to use tabs in new versions: https://ant.design/components/tabs

    Or you can just downgrade your Antd, but that’s not recommended.

    Login or Signup to reply.
  2. I think the problem is with Card.Body. There’s no export for Card.Body in antd, only Card.Meta and Card.Grid. I think that’s why it said the import is undefined. Thought TabPane is deprecated, it should not throw an error, there should only be a warning.

    Login or Signup to reply.
  3. The issue for your code is in line 17. The Card.Body is not exported by Antd and therefore not an ReactNode. Accessing Card.Body results in undefined and you are wrapping all the element inside an undefined, which is an error, remove Card.Body with other element like div or just use Card from antd, this will resolve your error.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search