How to put array coming from api in my component state using recompose?

33 views Asked by At

I was always working with React / Redux-Saga, recently I started working with recompose, It made me a little bit confused, I am still learning how to deal with data in this new approach to me, so before if I want to get data from my redux state and pass it to local state I do something like this :

class Comp extends Component {
    constructor(props){
       super(props);
       this.state = {
           data: this.props ? this.props.data :        
       }
    }

    // Or I can use componentWillReceive Props method to get the props and use setState to make my local state get data
    componentWillReceiveProps(props){
         this.setState({data: props.data});
    }

    render(){ 
        return (my UIs)
    }
}

function mapStatToProps(state){
   return { data: state.data }
} 

connect(mapStateToProps, null)(Comp);

Now I have to use an other architecture when I separate logic from data, a component that receives data and handle it ( Container ), and other just reading the data for most of the time.

I have to do something like this :

function mapStatToProps(state){
   return { data: state.data }
} 

const CompContainer = compose(
    connect(mapStateToProps, null),
    withState('data', ??, null ), // I don't know how to push data my props to here before rendering UI
    withProps(({data}) => ({data}))
)(CompUI);

And the CompUI has only jsx elements, or maybe it will have some events that I will execute by adding the withHandlers in my container.

As I mentionned in the comment in the second piece of code, I don't know how to pass data know to this component localState.

How can I achieve this ? Or there is now way to do this because we have to work only with functionnal components with this approach ?

Any help would be much appreciated.

0

There are 0 answers