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

Migrate to functional components - 2 #1811

Merged
merged 13 commits into from
Mar 15, 2022
Merged

Conversation

Inbal-Tish
Copy link
Collaborator

PeriodDay, Calendar

@Inbal-Tish Inbal-Tish changed the title Infra/more functional components Migrate to functional components - 2 Mar 2, 2022
}
const PeriodDay = (props: PeriodDayProps) => {
const {theme, marking, date, onPress, onLongPress, state, accessibilityLabel, testID, children} = props;
const dateData = date ? xdateToData(new XDate(date)) : undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I noticed this a few times, where you check if a value is undefined before passing it to the a util function.
Consider moving this logic to the util and return undefined if the argument passed is undefined.
It's very similar to how lodash works (they know how to handle undefined parameters)
Also, it makes the code a little cleaner

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changing the util to return undefined means to change the API for callback props that return this object. We can do it in V2

src/calendar/index.tsx Outdated Show resolved Hide resolved
src/calendar/index.tsx Outdated Show resolved Hide resolved
updateMonth(newMonth);
}, [currentMonth, updateMonth]);

const handleDayInteraction = (date: DateData, interaction?: (date: DateData) => void) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Notice that you might need to wrap this with useCallback.
Usually when one function depends on the other and the one is wrapped the other probably need to be wrapped as well.
Otherwise you'll have issues with old reference of functions being invoked with wrong closure data

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Inbal-Tish What about this one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Missed it. Done

@ethanshar
Copy link
Collaborator

@Inbal-Tish
One more thing I just noticed, In the HorizontalCalendarList example there are performance issues now.
All days are being rendered again, it doesn't reproduce on master.
I suspect it might related to the other comments I wrote.

@Inbal-Tish
Copy link
Collaborator Author

@ethanshar I would like to release this one on this cycle so we can have a full QA before we continue with other components since these are the basics that all the others rely on. Are you waiting for something on my end?

@ethanshar ethanshar merged commit cb8ae11 into master Mar 15, 2022
@Inbal-Tish Inbal-Tish deleted the infra/more_functional_components branch April 13, 2022 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants