React simple program using useState

import React, { useState } from 'react';

function ExampleComponent(props) {
  const [count, setCount] = useState(0);

  const incrementCount = () => {
    setCount(count + 1);
  };

  return (
    <div>
      <p>Count: {count}</p>
      <p>Message from Parent: {props.message}</p>
      <button onClick={incrementCount}>Increment Count</button>
    </div>
  );
}

function App() {
  const messageFromParent = "Hello from the parent component";

  return (
    <div>
      <ExampleComponent message={messageFromParent} />
    </div>
  );
}

export default App;

Do you have a question?

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

1 Like

yes
not getting how to use this

Can you say more? How are you attempting to use it? What is it doing? What should it be doing?

1 Like

how to use freecodecamp.org
is this for learning purpose or to post the code

1 Like

What part of freeCodeCamp.org are you asking about?

This forum is for learning purposes. Posting random code is not allowed.

how to use this for learning a specific topic

How to use what for learning a specific topic?

And what topic?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.