Manzana
Manzana

Reputation: 325

What is the optimal way to import Redux selectors in React components?

I'm in a project where a migration from context to Redux is being made. I noticed a lot of components use the same selectors so I was wondering what is the best way to reuse them in order to save space in memory. Selectors are simple, there are no special operations during the import.

So far what we're doing looks like this:

export const myApp: React.FC<MyAppProps> = (props) => {

    const dispatch = useAppDispatch()

    const {myVar} = useAppSelector((state) => state.vars)


    return (<div>...</div>)
}

We import the dispatch function in every component that uses it, together with any selectors we need.

Is there a way to optimize this process? Thanks in advance.

Upvotes: 0

Views: 107

Answers (1)

markerikson
markerikson

Reputation: 67469

I don't think there's any "savings in memory" to be had here.

You can certainly move the selector definitions into slice files, and import the selectors into the components. That's fine.

But that isn't going to affect "memory" usage at all.

Upvotes: 1

Related Questions