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

Update root component to React functional component. #6031

Open
divyanshu-patil opened this issue Nov 29, 2024 · 4 comments · May be fixed by #6033
Open

Update root component to React functional component. #6031

divyanshu-patil opened this issue Nov 29, 2024 · 4 comments · May be fixed by #6033

Comments

@divyanshu-patil
Copy link

divyanshu-patil commented Nov 29, 2024

Description:

The root component is currently implemented as a React class component. It should be updated to use a more modern functional component for consistency and to leverage hooks.
currently it looks like this

export default class Root extends React.Component<{}, IState> {
	private listenerTimeout!: any;
	private dimensionsListener?: EmitterSubscription

	constructor(props: any) {
		super(props);
		this.init();
		if (!isFDroidBuild) {
			this.initCrashReport();
		}
		const { width, height, scale, fontScale } = Dimensions.get('window');
		const theme = initialTheme();
		this.state = {
			theme: getTheme(theme),
			themePreferences: theme,
			width,
			height,
			scale,
			fontScale
		};
		if (isTablet) {
			this.initTablet();
		}
		setNativeTheme(theme);
	}

Additional context:

In the future, all components using class components should migrate to functional components to align with modern React practices.

@diegolmello
Copy link
Member

Can you do it?

@divyanshu-patil
Copy link
Author

assign it to me

divyanshu-patil added a commit to divyanshu-patil/Rocket.Chat.ReactNative that referenced this issue Nov 30, 2024
@Rohit3523
Copy link
Contributor

Shouldn't we follow the same component structure throughout the entire app, instead of having some as functional components and others as class components?

@divyanshu-patil
Copy link
Author

Shouldn't we follow the same component structure throughout the entire app, instead of having some as functional components and others as class components?

Yes, it's best to stick to one approach for consistency. Functional components are simpler, perform better, and work well with hooks, making them the preferred choice. While we can migrate gradually, moving all components to functional ones will make the app easier to maintain and align with current React best practices.

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 a pull request may close this issue.

3 participants