Skip to content

refactor: convert to functional component - #124

Open
ddanielsantos wants to merge 1 commit into
hungdev:masterfrom
ddanielsantos:master
Open

refactor: convert to functional component#124
ddanielsantos wants to merge 1 commit into
hungdev:masterfrom
ddanielsantos:master

Conversation

@ddanielsantos

@ddanielsantos ddanielsantos commented Aug 17, 2024

Copy link
Copy Markdown

Most react code written today uses functional components and hooks, with this PR, the main class component (Instagram) is converted to its equivalent functional component.

It does not lead to changes in behavior or improvements in performance, but it brings the code closer to the present day and will facilitate future maintenance by other people.

renderClose and renderWebview are still inner functions of the main component

@noghartt noghartt left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

let some review comments here

Comment thread Instagram.js
if (results.access_token) {
// Keeping this to keep it backwards compatible, but also returning raw results to account for future changes.
this.props.onLoginSuccess(results.access_token, results);
onLoginSuccess(results.access_token, results);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should we assume that onLoginSuccess is required every time?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

add a conditional to validate that onLoginSuccess exists

Suggested change
onLoginSuccess(results.access_token, results);
if (onLoginSuccess) {
onLoginSuccess(results.access_token, results);
}

Comment thread Instagram.js
if (responseType === 'code' && !appSecret) {
if (code) {
this.props.onLoginSuccess(code, results);
onLoginSuccess(code, results);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same here

Comment thread Instagram.js
onLoginSuccess(code, results);
} else {
this.props.onLoginFailure(results);
onLoginFailure(results);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same here

Comment thread Instagram.js

if (res) {
this.props.onLoginSuccess(res.data, results);
onLoginSuccess(res.data, results);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same here

Comment thread Instagram.js
onLoginSuccess(res.data, results);
} else {
this.props.onLoginFailure(results);
onLoginFailure(results);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same here

Comment thread Instagram.js
this.hide();
this.props.onLoginFailure(json);
hide();
onLoginFailure(json);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same here

Comment thread Instagram.js
webViewState.url === 'https://www.instagram.com/'
) {
this.setState({ key: key + 1 });
setKey((k) => k + 1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why exactly do you need to increase the key counter on that? just to force a rerender?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I didn't understand too

Should we do this change in this PR, since its only goal is to move from class to FC?

@hungdev

hungdev commented Aug 13, 2026

Copy link
Copy Markdown
Owner

I think this refactor may affect consumers that call the public imperative API through a ref:

ref.current.show()
ref.current.hide()

After converting the component to a function component, these methods need to be explicitly exposed. For React 18 and earlier, this requires forwardRef together with useImperativeHandle.

React 19 supports receiving ref as a prop in function components, so forwardRef is no longer necessary for React 19-only applications. However, this library does not declare React 19 as its minimum supported version, and not every consumer will be using React 19 yet.

Since the current class component is stable and the migration does not add a user-facing benefit, I think we should avoid merging this refactor for now unless it preserves the existing show() / hide() API across supported React versions and includes coverage for it. We can revisit the migration once React 19 adoption is more widespread and the package’s supported React-version policy is clear.

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.

3 participants