Home > Software design >  In VS Code, is there a way to set Prettier to not wrap function parameters in parantheses (when usin
In VS Code, is there a way to set Prettier to not wrap function parameters in parantheses (when usin

Time:01-04

I code in React and I always use arrow functions. When I use a single parameter in JS function, I like to leave it without parantheses. I always use arrow functions But I use Prettier frequently, and it wraps all my parameters in paranteheses automatically. Is there any way to make Prettier leave the parameter unwrapped?

CodePudding user response:

The option you're looking for is "Arrow Function Parentheses". Go to your Prettier config (e.g. in .prettierrc file) and add this key:

"arrowParens": "avoid"

Example of what this option does:

// Before formatting
const foo = (x) => 10;
const bar = (x, y) => 20;

// After formatting
const foo = x => 10;
const bar = (x, y) => 20;

Read more: How to add custom Prettier config

  • Related