Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

className does not exist on type 'IntrinsicAttributes & Props'

I have two components. One imports another. But typescript throws an error inside Login.tsx, saying:

"Property 'className' does not exist on type 'IntrinsicAttributes & Props'"

Login.tsx:

import React, { ReactElement } from 'react';
import Form from './Form/Form';

import styles from './Login.module.scss';

interface Props {}

function Login({}: Props): ReactElement {
  return (
    <div className={styles.container}>
      <Form className={styles.form}>Form</Form>
    </div>
  );
}

export default Login;

Form.tsx:

import React, { ReactElement } from 'react';

interface Props {
  children: React.ReactNode;
}

function Form({}: Props): ReactElement {
  return (
    <div>
      <h1>TESTY</h1>
    </div>
  );
}

export default Form;

How can I solve it? Thanks in advance for your time!

like image 361
Petro Ivanenko Avatar asked Oct 23 '20 09:10

Petro Ivanenko


1 Answers

My favorite way of doing it is

const Login : React.FC<Props> = ({}) => {
  return (
    <div className={styles.container}>
      <Form className={styles.form}>Form</Form>
    </div>
  );
}

export default Login;
like image 147
David Galoyan Avatar answered Oct 04 '22 13:10

David Galoyan