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

Refactor Redux in FileNode.jsx #3385

Closed

Conversation

Jatin24062005
Copy link
Contributor

Fixes #issue-2042

Changes:
Replaced connect HOC:
Removed mapStateToProps and mapDispatchToProps.

Introduced useSelector and useDispatch hooks for accessing the Redux store and dispatching actions.

Simplified Component Logic:

Directly accessed Redux state using useSelector:

const fileNode = useSelector((state) => state.files.find((file) => file.id === id));
const authenticated = useSelector((state) => state.user.authenticated);

Dispatched actions using useDispatch:

const dispatch = useDispatch();
dispatch(setSelectedFile(id));
Removed Boilerplate Code:

Eliminated the need for connect and higher-order components (HOCs).

Simplified the component export:
export default FileNode;

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test)
  • is from a uniquely-named feature branch and is up to date with the develop branch.
  • is descriptively named and links to an issue number, i.e. Fixes #123

@raclim
Copy link
Collaborator

raclim commented Mar 13, 2025

Thanks for giving this a shot!

This component is a bit tricky to work with! I tried to do a similar change a few months ago (https://github.com/processing/p5.js-web-editor/pull/3289/files), but ultimately has a few errors with it. Based on the attached issue, I think this might be an incomplete solution here since it aims to refactor the components to use Redux-Toolkit. I'm going to close this for now, but please feel free to look into how Redux Toolkit works!

@raclim raclim closed this Mar 13, 2025
@Jatin24062005
Copy link
Contributor Author

@raclim Thanks for your feedback! I’d love to better understand the expected approach for the Redux Toolkit migration. Would it be helpful if I opened a discussion to align on the best way forward?

Also, if there are specific issues related to this transition that need attention, I’d be happy to help tackle them. Let me know how I can contribute

@raclim
Copy link
Collaborator

raclim commented Mar 13, 2025

We do have a few open PRs (3121 - 3127) at the moment that's already started this process and has the attached issue for it, which I think is a good place to start looking as a reference!

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.

2 participants