Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress warning due to a third-party PropTypes library in react native

I got a plenty of warnings while using Stylesheet in React Native as following image.

Warning on iOS simulator

How to suppress it?

like image 367
William Han Avatar asked Aug 11 '16 23:08

William Han


People also ask

How do you stop showing warning in React Native?

The Yellow warning box in React Native can be both helpful and annoying. There are many errors that can be ignored but end up blocking necessary pieces of the application. To disable the yellow box place console. disableYellowBox = true; anywhere in your application.

Are PropTypes necessary?

Props and PropTypes are important mechanisms for passing read-only attributes between React components. We can use React props, short for properties, to send data from one component to another. If a component receives the wrong type of props, it can cause bugs and unexpected errors in your app.

What is isRequired in React?

isRequired means that props element defined is required to be passed from parent component. If you don't pass it, React will give you a warning message.

How do you use PropTypes in a functional component React?

import React from 'react'; import PropTypes from 'prop-types'; function List(props) { const todos = props. todos. map((todo, index) => (<li key={index}>{todo}</li>)); return (<ul></ul>); } List. PropTypes = { todos: PropTypes.


1 Answers

There is no way to disable warnings for a specific component, but you can disable different types of warnings in your app. To disable all warnings, use:

console.disableYellowBox = true;

To disable only certain warnings that start with a given string, specify an array of prefixes to filter out:

console.ignoredYellowBox = ['Warning: ...'];

For example, for the warning in the question you could write:

console.ignoredYellowBox = [
  'Warning: You are manually calling a React.PropTypes validation',
];
like image 173
ide Avatar answered Oct 20 '22 04:10

ide