1

My onClick function doesn't work and the problem is: "Line 17: 'propTypes' is not defined no-undef Line 18: 'propTypes' is not defined no-undef".

my "text:propType.string" and "color:propTypes.string" are on line 17 and 18. Thank you for helping me!

This is my Button.js file:

import React from 'react';
import PropTypes from 'prop-types';
const Button = ({color, text}) => {
    const onClick = () => {
        console.log('click')
    }
    
    return <button onClick={onClick} style={{backgroundColor:color}} className="btn">{text}</button>
        
}

Button.defaultProps = {
    color:'steelblue',

}
Button.propTypes={
    text:propTypes.string,
    color:propTypes.string,
}
export default Button

1 Answer 1

1

Just update propTypes to PropTypes:

Button.propTypes={
    text:PropTypes.string,
    color:PropTypes.string,
}
Sign up to request clarification or add additional context in comments.

1 Comment

omg it works! silly me! the spelling is so headache btw. thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.