-
Notifications
You must be signed in to change notification settings - Fork 593
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
Peer dependencies #587
base: master
Are you sure you want to change the base?
Peer dependencies #587
Conversation
Please, check this PR |
Closes #612, please merge it |
Unfortunately, author of the repository has not been active for a long time |
maybe there is a fork with react v18 support? |
The premise of this library is wrong/ obsolete. With the latest react
router the hooks give you the values you need.
…--
Sent from Mobile
|
@avindra I have complex selectors, which filters data based on url params (?a=1&b=2). Moving this logic into the a component is not an option for me. Do you have a solution? |
With import React from 'react';
import { useParams } from 'react-router-dom';
import { useSelector } from 'react-redux';
const UserProfile = () => {
const { userId } = useParams();
const user = useSelector((state) => state.users[userId]);
return (
<div>
<h1>{user.name}</h1>
<p>Email: {user.email}</p>
{/* Render more user details */}
</div>
);
};
export default UserProfile; Keep in mind you can swap |
If you still have a lot of class-based components (which BTW you should get rid of to keep on track with latest react)... then you can use import React from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
const UserProfile = ({ user }) => {
return (
<div>
<h1>{user.name}</h1>
<p>Email: {user.email}</p>
{/* Render more user details */}
</div>
);
};
const mapStateToProps = (state, ownProps) => {
const userId = ownProps.match.params.userId;
return {
user: state.users[userId],
};
};
export default withRouter(connect(mapStateToProps)(UserProfile)); |
@avindra yeah, thank, but this looks like workaround rather then good fix.
Cuz fix this way means that I add logic into the component which is needed only in selectors. I do not need those values in component, but in selectors only. That's why it's too early to say that
|
Happy to disagree. FWIW, I removed a hundred or so of these Once again, |
could you please explain in detail what exactly you did? I didn't get it. From the example you provided it looks like you did not remove the logic, but moved it into component instead. |
If you use As you noted, with the If you need to abstract the selector to a separate function, I suggest creating a hook. I have provided an example for this case.
import { useParams } from 'react-router-dom';
import { useSelector } from 'react-redux';
export function useUser() {
const { userId } = useParams();
const user = useSelector((state) => state.users[userId]);
return user;
}
import React from 'react';
import {useUser} from './hook.js'
const UserProfile = () => {
const user = useUser();
return (
<div>
<h1>{user.name}</h1>
<p>Email: {user.email}</p>
{/* Render more user details */}
</div>
);
};
export default UserProfile; |
@avindra thanks lot! This looks much better from what I thought initially. But again, create new hook just to filter the selector data based on query params looks less nice then incapsulate this logic in selectors. |
Updated peer dependencies
Support react 18.2.0 and react-redux 8.0.0
#585
#577