繁体   English   中英

country-state-city 根本不加载

[英]country-state-city does not load at all

在我的反应应用程序中,我不断遇到国家城市的问题。 拉取它的代码如下,错误就在它的正下方。 我没有丝毫线索,我一直在到处寻找。

import { useState, useEffect } from 'react';
import { Box, TextField, Button, InputAdornment } from '@mui/material';
import csc from 'country-state-city';

export const Markups = () => {

    const [country, setCountry] = useState({});

    useEffect(() => {
        const getStates = async() => {
            try {
                let country_abbrv = 'US';
                let country = await csc.getCountryByCode(country_abbrv);
                let temp_states = await csc.getStatesOfCountry(country.isoCode);

                console.log(temp_states);
            } catch (err) {
                console.log(err);
            }

        };
        getStates();
    })
TypeError: Cannot read properties of undefined (reading 'getCountryByCode')
    at getStates (index.js:13:1)
    at index.js:22:1
    at commitHookEffectListMount (react-dom.development.js:23142:1)
    at commitPassiveMountOnFiber (react-dom.development.js:24920:1)
    at commitPassiveMountEffects_complete (react-dom.development.js:24885:1)
    at commitPassiveMountEffects_begin (react-dom.development.js:24872:1)
    at commitPassiveMountEffects (react-dom.development.js:24860:1)
    at flushPassiveEffectsImpl (react-dom.development.js:27032:1)
    at flushPassiveEffects (react-dom.development.js:26978:1)
    at commitRootImpl (react-dom.development.js:26929:1)

根据他们的文档,默认导出中不存在该方法。 相反,它导出城市、国家等。

import { Country, State, City }  from 'country-state-city';
City.getCountryByCode(countryCode);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM