第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

React:從 uuid 開始不推薦使用深度要求,請要求頂級模塊

React:從 uuid 開始不推薦使用深度要求,請要求頂級模塊

慕碼人8056858 2022-05-22 16:01:45
我的 React 應(yīng)用程序成功顯示按鈕,但收到此錯誤。index.js:1const uuidv4 = require('uuid/v4');從 uuid@7.x 開始,不推薦使用需要 like 的深度。使用 Node.js CommonJS 模塊時請要求頂級模塊或捆綁瀏覽器時使用 ECMAScript 模塊import React, { Component } from 'react';import { Container, ListGroup, ListGroupItem, Button } from 'reactstrap';import { CSSTransition, TransitionGroup } from 'react-transition-group';import uuid from 'uuid/v4';class ShoppingList extends Component {    state = {        items: [            { id: uuid(), name: 'Eggs' },            { id: uuid(), name: 'Milk' },            { id: uuid(), name: 'Steak' },            { id: uuid(), name: 'Water' },        ]    }    render() {        const { items } = this.state;        return (            <Container>                <Button                  color="dark"                 style={{marginBottom: '2rem'}}                 onClick={() => {                    const name = prompt('Enter Item');                    if (name) {                        this.setState(state => ({                           items: [...state.items, { id: uuid(), name }]                         }));                    }                }}                >Add Item</Button>            </Container>        );    }}export default ShoppingList;我嘗試使用 'import { v4 as uuidv4 } from 'uuid';uuidv4();'但是我的按鈕不會出現(xiàn),我會得到錯誤:未捕獲的 ReferenceError:未定義 uuid也許我應(yīng)該得到這個錯誤?目前一切正常嗎?
查看完整描述

2 回答

?
慕慕森

TA貢獻(xiàn)1856條經(jīng)驗 獲得超17個贊

這在最近更新庫后發(fā)生了變化,現(xiàn)在您可以根據(jù)庫描述導(dǎo)入 uuid:


“從 uuid@7 開始,這個庫現(xiàn)在提供 ECMAScript 模塊構(gòu)建,它允許像 Webpack 和 Rollup 這樣的打包器進(jìn)行“tree-shaking”以刪除死代碼。相反,使用導(dǎo)入”


import { v4 as uuid_v4 } from "uuid";

uuid_v4()

...或者對于 CommonJS:


const { v4: uuid_v4 } = require('uuid');

uuid_v4();


查看完整回答
反對 回復(fù) 2022-05-22
?
慕碼人2483693

TA貢獻(xiàn)1860條經(jīng)驗 獲得超9個贊

您可以改用react -uuid

npm i react-uuid

用法

import uuid from "react-uuid";


查看完整回答
反對 回復(fù) 2022-05-22
  • 2 回答
  • 0 關(guān)注
  • 253 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號