javascriptreactjseslintvitereact-props

how fix 'is missing in props validation eslint react/prop-types' error?


'name' is missing in props validation eslint react/prop-types

'description' is missing in props validation eslint react/prop-types


export default function Note({name,description}) {
  return (
    <div>        
        <h1>{name}</h1>
        <p>{description}</p>
    </div>
  )
}
import Note from './Note'

export default function NoteList() {
  return (
    <div>
        <Note name="roze" description="Lorem ipsum dolor sit amet consectetur" />
        <Note name="sam" description="Lorem ipsum dolor sit amet consectetur" />
    </div>
  )
}

Solution

  • You can try prop-types package using this command

    npm install prop-types

    And then for your case you can use this code

      // Note.js
      import React from 'react';
      import PropTypes from 'prop-types';
    
     export default function Note({ name, description }) {
      return (
        <div>
          <h1>{name}</h1>
          <p>{description}</p>
        </div>
      );
      }
    
      Note.propTypes = {
      name: PropTypes.string.isRequired,
      description: PropTypes.string.isRequired,
     };
    

    NoteList.js Leave as is