24

I have a huge number of console errors like this appearing in my app:

Warning: React does not recognize the textStyle prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase textstyle instead. If you accidentally passed it from a parent component, remove it from the DOM element.

Ideally I would fix the errors but sadly that's not possible as I'm using Styled System with Styled Components: https://github.com/styled-system/styled-system/issues/1044

As a less than ideal workaround Id like to disable certain errors from the console for the development version of React. Can this be done?

Not sure if it matters but I'm using React Native Web.

3

1 Answer 1

32
+250

You can override the console.warn method with your own function that filters out the warnings you want to ignore:

const consoleWarn = console.warn;
const SUPPRESSED_WARNINGS = ['arning text - I will n'];

console.warn = function filterWarnings(msg, ...args) {
    if (!SUPPRESSED_WARNINGS.some((entry) => msg.includes(entry))) {
        consoleWarn(msg, ...args);
    }
};

console.warn('I\'ll appear as a warning');
console.warn('warning text - I will not');

I'm not sure which console method react is using internally, so you may need to do the same for console.info, console.log and console.error.

You can also just use the production version of react, which suppresses all warnings by default, but of course you can't pick and choose, you loose all warnings in that case.

Sign up to request clarification or add additional context in comments.

2 Comments

In TypeScript, this throws the error "Argument of type 'IArguments' is not assignable to parameter of type '[message?: any, ...optionalParams: any[]]'.ts(2345) Use the rest parameters instead of 'arguments'."
do you have to do this in every file?

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.