0

Не могу вывести props в консоль. Именно в функциональном компоненте.

В классовых все работает нормально. Вроде подключение к redux есть. Единственное что пишет, это то что props undifined

import { connect } from 'react-redux';

export function listСategories(props) {
  const string = 'Hello world';
  console.log(props.gamedata.numQues);
  return string;
}


const mapStateToProps = state => ({
  gamedata: state.questions.data,
  user: state.user.data,
  screen: state.screen.screenState,
  allquestions: state.allquestions.data,
});

export default connect(mapStateToProps)(listСategories);

Вот в классовом все нормально:

import React, { Component } from 'react';
import { styles } from '../styles';
import { View, Text } from 'react-native';
import { connect } from 'react-redux';

class Progressbar extends Component {
  constructor(props) {
    super(props);
    this.state = {

    };
  }

  render() {
    let result = [...Array(this.props.gamedata.numQues)].map((item, index, arr) => {
      let color;
      if(this.props.gamedata.right.includes(index)){
        color = 'green';
      }else if(this.props.gamedata.wrong.includes(index)){
        color = 'red';
      }else{
        color = 'blue';
      }
				return (
          <View key={index} style={{width: 20, height: 20, borderRadius: 100/2, backgroundColor: `${color}`, marginBottom: 10}} />
				)
		});

    return (
    <View style={{flexDirection: 'row', justifyContent: 'center', flexWrap: 'wrap'}}>
      {result}
    </View>
    );
  }
}


const mapStateToProps = state => ({
  gamedata: state.questions.data,
  user: state.user.data,
  screen: state.screen.screenState,
});


export default connect(mapStateToProps)(Progressbar);

1 ответ 1

0

В функциональном компоненте не используйте this. Вы же props аргументом получаете

export function listСategories(props) {
  const string = 'Hello world';
  console.log(props);
  return string;
}
1
  • Все равно undifined
    – sinevik
    29 июн 2018 в 8:49

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.