Skip to content

Comments

Add support for React components#5

Open
BrunnerLivio wants to merge 1 commit intoiatrophobic:mainfrom
BrunnerLivio:feature/components
Open

Add support for React components#5
BrunnerLivio wants to merge 1 commit intoiatrophobic:mainfrom
BrunnerLivio:feature/components

Conversation

@BrunnerLivio
Copy link

@BrunnerLivio BrunnerLivio commented Jan 28, 2024

related: #3

It's just an initial effort to give a baseline of the described feature :)

cc.ComponentNam
class ComponentName extends React.Component {
  render() {
    return (
      <div></div>
    );
  }
}

cc.ComponentName[name]
class ComponentName extends React.Component {
  render() {
    return (
      <div></div>
    );
  }
}

fc.ComponentName
const ComponentName = () => {
  return (
    <div></div>
  );
};

fc.ComponentName[firstName, lastName]
const ComponentName = ({firstName, lastName}) => {
  return (
    <div></div>
  );
};

"extension.generateReactComponentSnippet",
() => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd encourage using early returns instead of nesting your code, like you did in the extension.generateReactHookSnippet command.

This leads to much simpler code in my eyes and also decreases the cyclomatic complexity
CodeAesthetics made a video about it if you're curious: https://www.youtube.com/watch?v=CFRhGnuXG-4


let snippet = "";

if (componentType === "fc") {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be rewritten to use a switch/case instead or even better to use an appropriate data structure so you eliminate any branching code in the first place. But I leave that refactoring to another PR / to you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant