sorenlouv / react-redux-request

Declarative data fetching for React, stored in Redux.
MIT License
4 stars 2 forks source link

Redux context not found with latest React #1

Open enewhuis opened 5 years ago

enewhuis commented 5 years ago

The only way I can get this to work is by passing the store explicitly.

import React, { Component } from 'react'
import { Request } from 'react-redux-request'
import { ReactReduxContext } from 'react-redux'

const thunk = url => () => fetch(url).then(response => response.json())

class MyComponent extends Component {
  static contextType = ReactReduxContext;
  render() {
    return (
      <Request
        store={this.context.store}
        fn={thunk(`${window.location.origin}/api/profiles`)}
        id="profiles"
        render={({ status, data, error }) => <div>{status}</div>}
      />
    )
  }
}
sorenlouv commented 5 years ago

Hi there,

Thanks for taking an interest in this project. Unfortunately I don't maintain it actively any longer, since I have stopped using it myself.

If your react version supports hooks I recommend moving towards something like https://github.com/CharlesStover/fetch-suspense.

Personally I've created a custom hook that does something similar. It is not yet open-sourced separately but I might do that if there is interest.