React native 在访问redux存储时执行有限循环

React native 在访问redux存储时执行有限循环,react-native,react-redux,React Native,React Redux,我正在尝试创建一个应用程序,在当前模块中,我需要从redux商店获取productList列表。但是当我试图从存储读取时,整个组件开始了一个无限循环。如果我评论下一行,一切都会变得正常。我是个新手,不知道自己在这里做错了什么 const vendorProducts=useSelector(store=>store.productList.loadedProducts) import React,{useState,useffect}来自“React”; 从“react native”导入{Vi

我正在尝试创建一个应用程序,在当前模块中,我需要从redux商店获取productList列表。但是当我试图从存储读取时,整个组件开始了一个无限循环。如果我评论下一行,一切都会变得正常。我是个新手,不知道自己在这里做错了什么

const vendorProducts=useSelector(store=>store.productList.loadedProducts)

import React,{useState,useffect}来自“React”;
从“react native”导入{View、Text、StyleSheet、TouchableOpacity、FlatList};
从'react redux'导入{useDispatch,useSelector};
将*作为productListAction从“../store/actions/products”导入;
从“../Constants/Constants”导入常量;
常量产品=道具=>{
log('Hello');
const token=useSelector(store=>store.auth.token);
//const vendorProducts=useSelector(store=>store.productList.loadedProducts);
const dispatch=usedpatch();
useffect(()=>{
异步函数getProductList(){
让我们回应;
让产品列表;
试一试{
const BASEURL=Constants.BASE\u URL;
response=wait-fetch(BASEURL+'wp-json/wcfmmp/v1/products/'{
方法:“GET”,
标题:{
接受:'application/json',
“内容类型”:“应用程序/json”,
授权:“持票人”+代币,
},
});
productList=await response.json();
}捕获(错误){
控制台错误(error);
}
分派(productListAction.loadedProducts(productList));
}
getProductList();
});
返回(
产品
);
};
const style=StyleSheet.create({});
出口默认产品;

你介意分享你的
产品列表
操作和缩减器吗?你介意分享你的
产品列表
操作和缩减器吗?
import React, {useState, useEffect} from 'react';
import {View, Text, StyleSheet, TouchableOpacity, FlatList} from 'react-native';
import {useDispatch, useSelector} from 'react-redux';
import * as productListAction from '../store/actions/products';
import Constants from '../constants/constants';

const Products = props => {
  console.log('Hello');
  const token = useSelector(store => store.auth.token);
  //const vendorProducts = useSelector(store => store.productList.loadedProducts);
  const dispatch = useDispatch();

  useEffect(() => {
    async function getProductList() {
      let response;
      let productList;
      try {
        const BASEURL = Constants.BASE_URL;
        response = await fetch(BASEURL + 'wp-json/wcfmmp/v1/products/', {
          method: 'GET',
          headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
            Authorization: 'Bearer ' + token,
          },
        });
        productList = await response.json();
      } catch (error) {
        console.error(error);
      }
      dispatch(productListAction.loadedProducts(productList));
    }
    getProductList();
  });
  return (
    <View>
      <Text>Product</Text>
    </View>
  );
};

const style = StyleSheet.create({});

export default Products;