skip to Main Content

‘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>
  )
}

2

Answers


  1. 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,
     };
    

    and NoteList.js Leave as is

    Login or Signup to reply.
  2. The code is wanting you to create a type for the props being passed into the Note component. You can do so like this:

    type NoteProps = {
       name: string;
       description: string;
    }
    
    export default function Note({name,description}: NoteProps) {
      return (
        <div>        
            <h1>{name}</h1>
            <p>{description}</p>
        </div>
      )
    }
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search