最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - React "prop-types" not showing warning validation messages on bowser console - Stack Overflow

programmeradmin1浏览0评论

I have tried the following, expecting to have some kind of validation warning msg on the Chrome console, but nothing happens (console all crear) when not setting the "title" variable on the main.jsx FirstApp component

main.jsx

import React from 'react';
import ReactDOM from 'react-dom/client';
import {FirstApp} from './FirstApp';
ReactDOM.createRoot( document.getElementById('root') ).render(
    <React.StrictMode>
        <FirstApp/>
    </React.StrictMode>
);

FirstApp.jsx

import PropTypes from 'prop-types';
export const FirstApp = ({title}) => {
  return (
    <>
        <h1>{title}</h1>
        <h2>Hello World</h2>
    </>
  )
}
FirstApp.propTypes = {
  title: PropTypes.string.isRequired
}

I have checked the browser settings, reset to defaults with no result. The component is working as I am able to see Hello World. I'm using Vite and running: npm run dev. Here below my package.json dependencies:

"prop-types": "^15.8.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",

I have tried the following, expecting to have some kind of validation warning msg on the Chrome console, but nothing happens (console all crear) when not setting the "title" variable on the main.jsx FirstApp component

main.jsx

import React from 'react';
import ReactDOM from 'react-dom/client';
import {FirstApp} from './FirstApp';
ReactDOM.createRoot( document.getElementById('root') ).render(
    <React.StrictMode>
        <FirstApp/>
    </React.StrictMode>
);

FirstApp.jsx

import PropTypes from 'prop-types';
export const FirstApp = ({title}) => {
  return (
    <>
        <h1>{title}</h1>
        <h2>Hello World</h2>
    </>
  )
}
FirstApp.propTypes = {
  title: PropTypes.string.isRequired
}

I have checked the browser settings, reset to defaults with no result. The component is working as I am able to see Hello World. I'm using Vite and running: npm run dev. Here below my package.json dependencies:

"prop-types": "^15.8.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
Share Improve this question edited Feb 23 at 11:12 Antonio Retamosa asked Feb 23 at 10:53 Antonio RetamosaAntonio Retamosa 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default -1

I jave just found prop-types are no longer validated in React 19.

发布评论

评论列表(0)

  1. 暂无评论