Joff
Joff

Reputation: 12187

can I distribute a react component that uses redux?

I've got a big component that I am making that will take one large standardized object and display it. I will have many child components within the main distributed component and I don't want to have to make it ugly by typing in props all the way down the chain...

const User = ({ user }) => {
  return (
    <BasicInfo
      name={user.basic.name}
      tagline={user.basic.tagline}
      email={user.basic.email}
      ...more props
    >
    <OtherInfo
      infoprops={info}
      ...long list of props
    >
  )
}

It would end up being a very long list of props that might go 3 or 4 levels deep and I really don't want to have to keep track of what is passing what on manually...

I got used to using redux, so I could do something like connect() but can I use redux here with a distributed component? would the state of my one component be kept separate from the end users redux (if they are even using redux)?

Is this even wise? Maybe there is a a better way than using redux? Thanks

Upvotes: 0

Views: 122

Answers (1)

EnriqueDev
EnriqueDev

Reputation: 1247

I don't think its a good idea to use redux to make your component reusable since redux is based on a single store for a whole application so, if you create a store, the app would not be able to create its own.

Given that, I do think you could create your custom store using the Singleton pattern (as you usually would do with android) without forcing your possible users to add redux to their project just to use your component.

I can't guide you more without knowing your component hierarchy or behaviour.

Upvotes: 1

Related Questions