Conway's Game of Life as a React web app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Cell.tsx 567B

12345678910111213141516171819202122232425
  1. import React from 'react';
  2. interface Props {
  3. x: number;
  4. y: number;
  5. alive: boolean;
  6. disabled: boolean;
  7. toggle: (x: number, y: number) => void;
  8. cellSize: number;
  9. }
  10. const Cell = (props: Props) => {
  11. const { alive, toggle, x, y, disabled, cellSize } = props;
  12. return (
  13. <span
  14. onClick={() => (disabled ? null : toggle(x, y))}
  15. className={`cell ${alive ? 'alive' : 'dead'} ${
  16. disabled ? 'nonclickable' : 'clickable'
  17. }`}
  18. style={{ width: `${cellSize}px`, height: `${cellSize}px` }}
  19. ></span>
  20. );
  21. };
  22. export default Cell;