Wednesday, 1 August 2018

React : Result to 'sometime' kadang-kadang

Guna react untuk dapatkan kebarangkalian option akan keluar. ambil contoh macam menu..
Kadang-kadang hari ni ada ais krim, kadang-kadang takde..



import React from 'react';
import ReactDOM from 'react-dom';

// judgmental will be true half the time.
const judgmental = Math.random() < 0.5;

const favoriteFoods = (
  <div>
    <h1>My Favorite Foods</h1>
    <ul>
      <li>Sushi Burrito</li>
      <li>Rhubarb Pie</li>
      { !judgmental && <li>Nacho Cheez Straight Out The Jar</li> }
      <li>Broiled Grapefruit</li>
    </ul>
  </div>
);

ReactDOM.render(
 favoriteFoods, 
 document.getElementById('app')
);


{ !judgmental && <li>Nacho Cheez Straight Out The Jar</li> }

..akan keluar kadang-kadang dengan kebarangkalian keluar sebanyak 0.5 atau  50%

My Favorite Foods

  • Sushi Burrito
  • Rhubarb Pie
  • Broiled Grapefruit
{ !judgmental && <li>Nacho Cheez Straight Out The Jar</li> }

..tak keluar.

My Favorite Foods

  • Sushi Burrito
  • Rhubarb Pie
  • Nacho Cheez Straight Out The Jar
  • Broiled Grapefruit
{ !judgmental && <li>Nacho Cheez Straight Out The Jar</li> }

..keluar.
Result keluar seperti ini kerana adanya variable 
// judgmental will be true half the time.
const judgmental = Math.random() < 0.5;

email mailto: pretext

 <a href="mailto:designoutsourced.com+info@gmail.com?subject=Maklumat%20lanjut%20pakej&body=Hai,%20saya%20berminat%20tahu%20lebi...