我有两个减速器我想在一个容器来使用这两者,但它只是拉从一个Redux的多个连接到一个容器
这是在减速机结合
import { combineReducers } from "redux"
import cityName from "./weather-apiReducers"
import nameOfCity from "./weather-apiReducers"
import weatherDescription from "./weather-apiReducers"
import windSpeed from "./weather-apiReducers"
import temperature from "./weather-apiReducers"
import maxTemperature from "./weather-apiReducers"
import minTemperature from "./weather-apiReducers"
import isClicked from "./weather-apiReducers"
import name from "./weather-apiReducers"
export default combineReducers({
cityName,
nameOfCity,
weatherDescription,
windSpeed,
temperature,
maxTemperature,
minTemperature,
isClicked,
name
})
减速
export default function reducer(state={
nameOfCity: "",
weatherDescription: "",
windSpeed: "",
temperature: "",
maxTemperature: "",
minTemperature: "",
}, action) {
switch (action.type){
case "FETCH_WEATHER_DATA": {
return {...state,
fetching: true
}
}
case "FETCH_WEATHER_REJECTED": {
return {...state,
fetching: false,
error: action.data
}
}
case "FETCH_WEATHER_DATA_FULFILLED": {
return {...state,
fetching: false,
fetched: true,
nameOfCity: action.results.city.name,
weatherDescription: action.results.list[0].weather[0].description,
windSpeed: action.results.list[2].wind.speed,
temperature: action.results.list[0].main.temp,
maxTemperature: action.results.list[0].main.temp_max,
minTemperature: action.results.list[0].main.temp_min
}
}
case "UPDATE_INFO_DATA_FULFILLED": {
return {...state,
nameOfCity: action.results.cityName,
}
}
case "HANDLE_CITY_NAME": {
return {...state,
cityName: action.value,
}
}
}
return state;
}
export function reducerAList(state={
id: "",
name: ""
}, action) {
switch (action.type){
case "FETCH_A_DATA": {
return {...state,
fetching: true
}
}
case "FETCH_A_REJECTED": {
return {...state,
fetching: false,
error: action.data
}
}
case "FETCH_A_DATA_FULFILLED": {
return {...state,
fetching: false,
fetched: true,
name: action.resultsP.name
}
}
}
return state;
}
店
import { applyMiddleware, createStore } from "redux"
import logger from "redux-logger"
import thunk from "redux-thunk"
import promise from "redux-promise-middleware"
import reducer, {reducerAList} from "./reducers"
const middleware = applyMiddleware(thunk, promise(), logger())
export default createStore(reducer, reducerAList, middleware)
容器
import React, { Component } from 'react';
import './App.css';
import {FormContainer} from './containers/FormContainer';
import WeatherInfo from './components/WeatherInfo';
import {fetchWeatherData} from "./actions/weather-apiActions";
import {fetchAList} from "./actions/weather-apiActions";
import {connect} from "react-redux"
@connect((store) => {
return {
nameOfCity:store.nameOfCity.nameOfCity,
weatherDescription:store.weatherDescription.weatherDescription,
windSpeed:store.windSpeed.windSpeed,
temperature:store.temperature.temperature,
maxTemperature:store.maxTemperature.maxTemperature,
minTemperature:store.minTemperature.minTemperature,
name:store.name
}
})
内进行名称集装箱此控制台日志给出不确定的,但对于这些变量的其余它给了什么是连接给出。它根本不听名字变量。我的问题是如何将这种第二减速器与容器
render() {
const { cityName, nameOfCity, weatherDescription, windSpeed, temperature, maxTemperature, minTemperature, name} = this.props;
console.log(name);
}
您需要使用reducer和reducerAList制作combinedReducer – daniloprates