Skip to content

Refactor StoryDescription class to function component #996

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

Merged
merged 3 commits into from
May 9, 2025

Conversation

julialbq
Copy link
Collaborator

What this PR do ?

Updates StoryDescription into a function component.

Related Issues

Update React classes to function components

Screenshots (if applicable)

Additional Notes (if any)

/>
);
}
const descriptionContent = () => (
Copy link
Contributor

@wrspada02 wrspada02 Mar 13, 2025

Choose a reason for hiding this comment

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

Do you think we should use memo approach here to avoid re-rendering?

cc: @talyssonoc

Copy link
Member

Choose a reason for hiding this comment

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

For both cases, I think memo won't make a different in re-rendering since it won't break the way React compares elements.

But I think we could avoid having these functions at all and use a ternary directly in the bottom part of the component. To improve even more, we could move the value of isNew || editingDescription to a variable, like const showDescriptionInput = isNew || editingDescription.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the input, guys. I've updated the PR with the suggested changes.

isNew,
editingDescription,
}) => {
const editDescription = () => (
Copy link
Contributor

@wrspada02 wrspada02 Mar 13, 2025

Choose a reason for hiding this comment

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

Do you think we should use memo approach here to avoid re-rendering?

cc: @talyssonoc

description,
onClick,
isNew,
editingDescription,
Copy link
Contributor

Choose a reason for hiding this comment

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

We could rename this to isEditingDescription

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Couldn't commit this change for some eslint issue in some files, but the issue doesn't seem to be related to the change itself... seems to be preexistent. We can talk more about it, if you wish!

{I18n.t('activerecord.attributes.story.description')}
</label>
<br />
{isNew || editingDescription ? editDescription() : descriptionContent()}
Copy link
Contributor

Choose a reason for hiding this comment

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

Move isNew || editingDescription to a new variable const isToRenderEditDescription : boolean = sNew || editingDescription; and also renders those components straightforward not calling functions

@julialbq julialbq force-pushed the refactor/storydescription-class-to-function branch from fa689ca to 8aad9c8 Compare March 25, 2025 16:48
@talyssonoc talyssonoc merged commit d73df1b into master May 9, 2025
2 of 3 checks passed
@talyssonoc talyssonoc deleted the refactor/storydescription-class-to-function branch May 9, 2025 04:38
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.

5 participants