前提・実現したいこと
Reactで非常に簡易な計算アプリを作っています。
stateに配列を入れ、Recharts.jsを使用してグラフを描画したいです。
Rechartsの呼び出し結果、画面は何も表示されず、Chromeのコンソールを確認すると以下のようなメッセージが表示されております。
何が原因か、不明ですので、お力添えいただきたいです。
発生している問題・エラーメッセージ
Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details. * Move data fetching code or side effects to componentDidUpdate. * If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state * Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder. Please update the following components: LineChart printWarning @ react-dom.development.js:12029 lowPriorityWarning @ react-dom.development.js:12050 push../node_modules/react-dom/cjs/react-dom.development.js.ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings @ react-dom.development.js:12217 flushRenderPhaseStrictModeWarningsInDEV @ react-dom.development.js:24481 commitRootImpl @ react-dom.development.js:23738 unstable_runWithPriority @ scheduler.development.js:674 runWithPriority$2 @ react-dom.development.js:11834 commitRoot @ react-dom.development.js:23723 runRootCallback @ react-dom.development.js:22809 (anonymous) @ react-dom.development.js:11886 unstable_runWithPriority @ scheduler.development.js:674 runWithPriority$2 @ react-dom.development.js:11834 flushSyncCallbackQueueImpl @ react-dom.development.js:11881 flushSyncCallbackQueue @ react-dom.development.js:11869 discreteUpdates$1 @ react-dom.development.js:22941 discreteUpdates @ react-dom.development.js:2440 dispatchDiscreteEvent @ react-dom.development.js:6254
該当のソースコード
import React from 'react'; import './App.css'; import { LineChart, Line, CartesianGrid, XAxis, YAxis, Tooltip, ResponsiveContainer } from 'recharts'; class App extends React.Component{ constructor(props){ super(props); this.state={ rechartsData:[], }; } handleSubmit() { for (let count = 1; count <= 10; count++) { this.state.rechartsData.push({ data: count, hoge: count*count }); } } /* メイン処理 */ render(){ return( <div className="row no-gutters"> <div className="col-xl-8"> <div className="container-fluid"> <div className="col mb-4 shadow mt-2 pt-2 pb-4 rounded"> ここにグラフが出る!! <ResponsiveContainer width="95%"> <LineChart data={this.state.rechartsData} // 表示するデータ margin={{top: 5, right: 50, left: 50, bottom: 25}}> <XAxis // X軸 dataKey="data" /> <YAxis /> <CartesianGrid /> <Tooltip /> <Line name="乗算" dataKey="hoge" stroke="salmon" // 線の色 unit="万円" //単位 /> </LineChart> </ResponsiveContainer> </div> </div> </div> </div> ); } } export default App;
試したこと
補足情報(FW/ツールのバージョンなど)

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。