Mindaugas
Mindaugas

Reputation: 1183

Cannot get value from Global State(Redux)

I am having trouble creating this shared component in my project. This is simplified version of its code:

import React from 'react';
import { View } from 'react-native';
import { connect } from 'react-redux';

function mapStateToProps(state) {
  return {
    platform: state.device.get('platform') //defines if iOS or Android
  };
}

export function SharedView({ theme, ...props }) {
  return <View {...props}>{theme}</View>;
}

export default SharedView(
  connect(mapStateToProps, null)
);

As I try to add console.log or alert inside of my mapStateToProps I get nothing and it seems I can not see it from my SharedView. I know I could rewrite it to class SharedView extends Component { ..., but for certain reasons I need to keep the format.

Any ideas how to get this global state value?

Upvotes: 0

Views: 493

Answers (1)

nanobar
nanobar

Reputation: 66405

connect is a higher order function - your component is supposed to be wrapped in it not the other way around.

export default connect(mapStateToProps)(SharedView);

Upvotes: 2

Related Questions