Mr. J
Mr. J

Reputation: 1839

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 enter image description here

How am I screwing this up?

Upvotes: 0

Views: 174

Answers (1)

Wouter van Nifterick
Wouter van Nifterick

Reputation: 24086

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.

Upvotes: 2

Related Questions