簡體   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