SPFx coding guidelines

Copper Contributor

Morning everyone,


We are in the middle of process of preparing migration our logic from typicall react components (React, Typescript and so on) to SPFx components and we are trying to make them maintainable as much as possible. So, I have several questions, may be you can help me with them:

  • code guidelines - you know, I've found several variants TSLint' rules for TS: MS recommended rulesetgithub' TS project coding guidelines and rules within SPFx project itself. Could you suggest which variant are more useful in terms SPFx components?
  • component structure - there are several variants: typical React component with state and props types (or interfaces?) within one file or SPFx 'way' with interfaces and classes divided into several files. Do you know what was the goal for such approach? I mean SPFx...

Thank you!

1 Reply
TSLint rules is really up to you, but I would stick to the ones that come with SPFx solutions instead of using the ones you mentioned.
TSLint config files are created inside the Config folder on SPFx solutions, so if you are using TSLint extension for VSCode it will not work by default. I have created a blog post with a simple workaround if you need this scenario to work: https://joelfmrodrigues.wordpress.com/2017/12/06/tslint-spfx/

Regarding component structure, it's again up to you. I personally prefer to have multiple files with small blocks of code than having a long file with multiple entities. I find it easier to maintain.
There's really no right or wrong answer here. Give both a try and pick the one that you feel better with :)