Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot read property 'dispatch' of undefined'. React

Following is the code that I am using. I am getting an error like Uncaught TypeError: Cannot read property 'dispatch' of undefined. I also want to dispatch an action.

import { connect } from 'react-redux'
let SearchBar = ({ dispatch }) => {
    let input
    return (
       <div>
           <form>
              <input type="text" placeholder="Search"  />
              <p>
                 <input type="checkbox" />
                 {' '}
                 Free
              </p>                
           </form>
       </div>
   )
}

SearchBar = connect()(SearchBar)
export default SearchBar()
like image 553
user1637909 Avatar asked Oct 17 '22 16:10

user1637909


1 Answers

A couple of things I notice immediately with your code example:

First of all the connect function requires some parameters in the first parenthesis, even if that parameter is a null, also I don't think you need the parentheses on the export line. Try replacing those last two lines with something like this:

export default connect(null)(SearchBar);

see if that makes any difference.

like image 104
Drum Avatar answered Nov 15 '22 07:11

Drum