Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for React components #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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