I am not sure why I get the error. Unhandled Rejection (Error): Given action "SET_CARS", reducer "cars" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.
REDUCERS
import { SET_CARS} from "../actions";
import { combineReducer } from "redux";
function cars(state = [], action) {
switch (action.type) {
case SET_CARS:
return
action.items;
default:
return state; }
}
const rootReducer = combineReducers({
cars
});
export default rootReducer;
ACTIONS
export const SET_CARS = 'SET_CARS';
export function setCars(items){
return {
type: SET_CARS ,
items
}
}
SearchCars
class SearchCars extends Component {
constructor() {
super();
this.state = {
tansmition: ""
};
}
search() {
let { tansmition } = this.state;
const url = `http://localhost:4000/vehicles/?
transmission=${tansmition}`;
fetch(url, {
method: 'GET'
})
.then(response => response.json())
.then(json => {
this.props.setCars(json.results)
})
}

ASI strikes again.
return
action.items;
This gets interpreted as:
return;
action.items;
Put them together on one line and it should work. I'd also consider using a formatter like prettier. It'll help yourself and others looking at your code to see bugs like this more easily.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With