score:2
Accepted answer
you can pass the argument postid as the first argument:
//pass in postid and return a selector function
export const makeselectsublivestreamviews = (postid) => createselector(
[selectsublivestream],
(sublivestream) => sublivestream[postid]?.views || 0
);
in your component:
//you need to recreate the selector function when postid chages
// or you'll get the wrong data
const selectsublivestreamviews = usememo(
()=>makeselectsublivestreamviews(postid), [postid]
);
//no need to pass postid again, code looks a little cleaner
const views = useselector(selectsublivestreamviews);
here are some examples how i use reselect with react-redux.
Source: stackoverflow.com
Related Query
- Use Reselect with ownProps for best practice?
- What is the best practice with React for importing a large static array to use in a select field?
- What is the best practice to use Oauth2, React, Node.js and Passport.js to authenticate user with Google sign on button?
- Reactjs: What's best practice for working with class vs functional components?
- React - Best practice for application with different entry points/sections
- How can i use the same class with differents mapDispatchToProps - Best practice
- Can we use Reselect memoization with redux for every single selector (even the silmplest getters)?
- best practice for calling a callback with parameters in react js
- best practice for using useEffect hook with multiple components
- Best practice for making small changes in UI with React and Redux
- Which is the best Practice for localisation ? By Using DB along with cache or Property file kept outside the war
- What is the best practice for reusing components across fragments with React/Relay/Typescript?
- Is some plugin or best practice for Gatsby to the creation of each build with a different language?
- React hooks: what is best practice for wrapping multiple instances of a hook with a single hook?
- Best Practice for handling consecutive identical useFetch calls with React Hooks?
- Best practice for conditional rendering of children elements in ReactJs with Redux connect?
- Best practice interface for custom hooks with function arguments
- How can I use multiple refs for an array of elements with hooks?
- Use reselect selector with parameters
- How do I use for loops with react?
- Best practice for ReactJS form components
- Between NativeBase and Shoutem, which is best to use for React Native?
- Best practice for an "empty" component - null? empty div? (A valid React element (or null) must be returned)
- Why is it best practice to surround JSX assigned to variables with parenthesis?
- Best practice for Next.js data fetching inside a component
- How to use typescript with the definition of custom styles for a select using react-select
- Best practices for refetching part of a GraphQL query with Apollo?
- How to use React Hooks Context with multiple values for Providers
- Is there a secure way to use React.js with a Python Flask backend for a multi-user, password protected site
- NextJS best practice for handling "Server Error" and "Client side error"
More Query from same tag
- React hook - onFocus and onBlur
- Function outside React class method undefined
- Unit Testing React HashRouter with Jest
- react inline function in jsx in one line
- React Formik Warning: A component is changing an uncontrolled input to be controlled
- Unable to find an error
- How to fetch data from API using id in reactJS?
- How to add description in React Storybook -> showInfo
- why in react js showing index.html tags for seo if we navigating to other pages?
- How do i wrap 2 Routes with a context in React router v6
- Unable to render collection data from firebase in react
- Passing context to a dynamically added child in ReactJS
- White Screen after npm run build React
- Apply Class if Child element exist in a loop for mega menu with React
- Submit button erases all checked boxes in material ui table
- Typescript module: Export interface and all its props
- Why is video not displaying when user joins room?
- How to toggle Modal once I receive the props inside Modal.jsx
- How to make new axios request when onChange is triggered?
- Stateful React component with async function failing Jest test
- how to create cascading dropdown lists in react
- redux update state value without changing initial state
- redux thunk wait data from a dispatch before to do an another dispatch
- Footer overlapping content when trying to make it stay at the bottom of the page
- Postman Error [err_http_headers_sent]: cannot set headers after they are sent to the client Using ReactJS & NodeJS
- Why does flow make me check for an undefined value that is already defined?
- React: Dynamic route not re-rendering correctly
- Populating React Dropdown Getting Error #31
- Test connected component in React/Redux
- React - Error: Invariant failed: You should not use <Link> outside a <Router>