简体   繁体   中英

Cannot call Function within Another Function - React.JS

I have the following code in a basic react app

import React from 'react';
import './App.css';

function genColor() {
  return <div style="#000000">Test</div>;
}

function App() {
  return (
    <div className="App">
      {this.genColor()}
    </div>
  );
}

export default App;

Calling genColor in the App function, but get在此处输入图像描述

How am I screwing this up?

You've created a global function, but you're calling it as if it's a member of App.

So either move the function to the App class, or remove this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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