Skip to content

Don't throw error if the store isn't in the context #38

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

Closed
wants to merge 1 commit into from

Conversation

jhollingworth
Copy link
Contributor

I've written a smaller wrapper around the connect component which, amongst other things, allows you to skip all the redux stuff and just render the inner component. This can be really helpful when you don't want to mess with setting up contexts, etc and test the render.

@dataful
class User extends React.Component {
  static data = {
    user: ({users}, {userId}) => users[userId]
  }

  static actions = {
    updateUser
  }

  render () {
    const {
      data: {
        user
      }
    } = this.props

    return <div className='User'>{user.name}</div>
  }

  onClick () {
    this.props.actions.updateUser()
  }
}


const actions = {
  updateUser: sinon.spy()
}

const data = {
  user: {
    id: 123,
    name: 'Foo'
  }
}

<User actions={actions} data={data} />

The issue is connect requires that context.store is there. Something I'd ideally like to avoid if possible for ease of testing. Would it be OK if we just did nothing if the store isn't in the context?

@gaearon
Copy link
Contributor

gaearon commented Aug 9, 2015

Let's do it another way: allow store to be passed as a prop to any connect()ed component. If it is passed, it will be used instead of context.store. Would you update your PR to implement this?

@jhollingworth
Copy link
Contributor Author

Closing in favour of #44

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