首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何应对世博会中的需求循环警告

问如何应对世博会中的需求循环警告
EN

Stack Overflow用户
提问于 2021-04-16 16:07:04
回答 1查看 5.4K关注 0票数 3

我得到了这个error.ErrorImg,这是要求循环错误,但是我找不到原因。我想通过ListItem使用View.js组件通过component.js,并且我已经像这样使用了从‘./components/’;导入{ListItem }的组件。结果是好的,但有这个警告,我想修复。请帮帮我。

需求周期: Components.js->

代码语言:javascript
复制
import Button from './Button';
import Select from './Select';
import Icon from './Icon';
import Tabs from './Tabs';
import Product from './Product';
import Drawer from './Drawer';
import Header from './Header';
import Switch from './Switch';
import ListItem from './ListItem';
import HorizontalListItem from './HorizontalListItem';
export {
    Button,
    Select,
    Icon,
    Tabs,
    Product,
    Drawer,
    Header,
    Switch,
    ListItem,
    HorizontalListItem,
};```

View.js->

```const renderPatientsList = () => {
代码语言:javascript
复制
  return(
代码语言:javascript
复制
    <Block style={{ paddingHorizontal: theme.SIZES.BASE }}>
代码语言:javascript
复制
        <ScrollView vertical={true} showsVerticalScrollIndicator={false} style={{marginBottom: theme.SIZES.BASE * 3}}>
代码语言:javascript
复制
            <ListItem product={products[0]} horizontal />
代码语言:javascript
复制
            <ListItem product={products[1]} horizontal />
代码语言:javascript
复制
            <ListItem product={products[2]} horizontal />
代码语言:javascript
复制
        </ScrollView>    
代码语言:javascript
复制
    </Block>
代码语言:javascript
复制
  )

}`

ListItem.js -->

代码语言:javascript
复制
import { withNavigation } from '@react-navigation/compat';
import { StyleSheet, Dimensions, Image, TouchableWithoutFeedback } from 'react-native';
import { Block, Text, theme } from 'galio-framework';
import { Icon } from '../components/';
import { LinearGradient } from 'expo-linear-gradient';

const { width } = Dimensions.get('screen');

const ListItem = props => {
  const { navigation, product, horizontal, full, style, priceColor, imageStyle, time, unReaden, weekday } = props;
  const imageStyles = [styles.image, full ? styles.fullImage : styles.horizontalImage, imageStyle];

  return (
        
      <Block row={horizontal} card flex style={[styles.product, styles.shadow, style]}>
          <TouchableWithoutFeedback onPress={() => navigation.navigate('Product', { product: product })}>
            <Block style={[styles.imageContainer, styles.shadow]}>
              <Image source={{ uri: product.image }} style={imageStyles}/>
            </Block>
          </TouchableWithoutFeedback>
          <TouchableWithoutFeedback onPress={() => navigation.navigate('Product', { product: product })}>
            <Block flex={3}>
              <Text size={16} style={styles.userName}>{product.title}</Text>
              <Block flexDirection={'row'}>
                <Icon name="photo" family="font-awesome" color={theme.COLORS.MUTED} size={theme.SIZES.BASE} style={styles.icons}> </Icon>  
                <Icon name="check" family="font-awesome" color={theme.COLORS.MUTED} size={theme.SIZES.BASE} style={styles.icons}> </Icon>  
                <Text size={16} muted={!priceColor} color={priceColor}>${product.price}</Text>
              </Block>
            </Block>
          </TouchableWithoutFeedback>
          <TouchableWithoutFeedback onPress={() => navigation.navigate('Product', { product: product })}>
            <Block flex={1}>
              <>
                {(product.time) ? (
                  <Text size={12} style={styles.times} color={"#06D81E"}>{product.time}</Text>
                ) : (
                  <Text size={12} style={styles.times} color={"#000"}>{product.weekday}</Text>
                )}
              </>
              
              <Block style={{borderRadius: 100, backgroundColor: "#06D81E", width: theme.SIZES.BASE * 1.2, height: theme.SIZES.BASE * 1.2, position: "absolute", right: theme.SIZES.BASE, bottom: theme.SIZES.BASE}}>
                <Text size={12} center style={{justifyContent: 'center', alignItems: 'center'}} color={"#FFF"} fontWeight={"semiBold"}>{product.unReaden}</Text>
              </Block>
            </Block>
          </TouchableWithoutFeedback>
      </Block>
  );
}```


  [1]: https://i.stack.imgur.com/rDB6i.png
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-16 18:11:39

您得到了要求循环警告,因为您最终创建了一个循环( ListItem.js中的Component.js和Component.js中的ListItem.js中的请求)

在ListItem.js中,

代码语言:javascript
复制
import {Icon} from Icon.js

总体思路是将模块写入另一个文件并从其中导入该模块。

有关详细解释,请参见此:Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67128632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档