rbi-learning / Today-I-Learned

1 stars 0 forks source link

Today I Learned August 24th #168

Open farhan310 opened 4 years ago

farhan310 commented 4 years ago

Today I Learned:

React

Here is an example of using React in order to change an object once a button is clicked:

const Product = props => {
  const [isProductCooked, setIsProductCooked] = React.useState(false);
  const { raw, cooked } = props;

  const cookTheProduct = () => setIsProductCooked(true);

  return (
    <div>
      <h1 id="product">{isProductCooked ? cooked : raw}</h1>
      <button type="button" onClick={cookTheProduct} disabled={isProductCooked}>
        {isProductCooked ? 'Cooked' : 'Cook it!'}
      </button>
    </div>
  );
};