gpt4 book ai didi

create-react-app - 'reportWebVitals' 未定义

转载 作者:行者123 更新时间:2023-12-04 15:58:01 26 4
gpt4 key购买 nike

来自 this section , create-react-app说过:

By default, Create React App includes a performance relayer thatallows you to measure and analyze the performance of your applicationusing different metrics.

To measure any of the supported metrics, you only need to pass afunction into the reportWebVitals function in index.js:

reportWebVitals(console.log);

This function is fired when the finalvalues for any of the metrics have finished calculating on the page.You can use it to log any of the results to the console or send to aparticular endpoint.


但是,当我将上述代码行添加到 index.js 中时,我有一个错误:

'reportWebVitals' is not defined


我的 index.js来源:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(
<Provider>
<App/>
</Provider>,
document.getElementById('root')
);

reportWebVitals(console.log);

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: http://bit .ly/CRA-PWA
serviceWorker.unregister();

最佳答案

我发现 reportWebVitals存在于 create-react-app 的新版本中(4.0.0)。所以为了使用reportWebVitals , 我创建了新的 create-react-app并复制 reportWebVitals.js进入我的项目,它奏效了。

关于create-react-app - 'reportWebVitals' 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64941176/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com