0

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?

1
  • Change to {genColor()} or more appropriately, <genColor /> Commented Jun 11, 2020 at 10:31

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.