A
A
Arti-Jack2018-04-16 01:04:38
JavaScript
Arti-Jack, 2018-04-16 01:04:38

Why is undefined being passed to my props?

There is a React application code
Entry point:

import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { createStore } from 'redux'; 
import reducer from './store/reducers'
import App from './App.js';


let store = createStore(reducer);


render(
  <Provider store={store}>
          <App />
  </Provider>, 
  document.getElementById('root')
);

Reducer:
export default const taskReducer = (state = [], action) => {
  switch (action.type) {
    case 'ADD_TASK':
      return [...state,
              action.payload];
      break;


    default:
      return state;  
  }
}

Component:
import React from 'react'
import { connect } from 'react-redux'

class App extends React.Component {
  render() {
console.log(this.props.entryText) // undefined!
    return (
      <div>
        <input type='text' placeholder='Add your task here' />
        <button >Add</button>
        
      </div>
    )
  }
}

export default connect(state => {entryText: state }, dispatch => { })(App)

Why is the state of the store not being passed to the props of the component via mapStateToProps? What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

7 answer(s)
E
eternalSt, 2018-04-16
@Arti-Jack

// Вот так вот попробуй
export default connect(state => ({entryText: state }), dispatch => { })(App)

// Вместо
// export default connect(state => {entryText: state }, dispatch => { })(App)

I don't think explanations are needed

D
Dasha Tsiklauri, 2018-04-16
@dasha_programmist

when you inherit, you need to call the constructor of the base class

constructor(){
super();
}

O
Oleg, 2014-03-23
@ruslite

startandroid.ru/ru/articles/listofarticles/284-zna...

I
IURIA, 2014-03-23
@GxocT

Sublime Text

S
Strange, 2014-03-23
@Strange

It is best to use the native language of the system (performance, stability, predictability).
If you need to fumble code between platforms, it makes sense to look towards xamarin .
I made an HTML & JS application using Backbone, it certainly worked, but then I rewrote it in Java.

W
wolf-9830, 2014-03-23
@wolf-9830

I can offer C++ and SDL2, full cross-platform, however, a bit of a chore.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question