Be A React Dev

Game View - Game Wrapper Rock Paper Scissors

12-Jun-2023


Amazon Prime

typescript plus react

What you will be building

Please check this link: Rock Paper Scissors Game

Game Wrapper

The game wrapper is a simple view component used to provide an encasement around a few other components.

view/wrapper.tsx file

import React, { ReactElement } from 'react';
//  chakra-ui
import { Box } from '@chakra-ui/react';

interface Props {
  children: ReactElement;
}

const DisplayWrapper = (props: Props) => {
  const { children } = props;

  return (
    <Box display="flex" justifyContent="center" w="100%">
      {children}
    </Box>
  );
};

export default DisplayWrapper;

The only thing particularly special about this component is that is uses the Box component from Chakra UI .

If you are not familiar with React, you may be wondering what children is. We are expecting React elements to be passed into this component from the Game Entry component.

Therefore the interface for children is declared (and not optional - optional interfaces are indicated with a question (?) mark), and we use the ReactElement definition in this case.

Job done!


Get Cool Swag

If you are finding this content useful (or maybe you are just a nice person or maybe you just like my merch) I would be greatful if you headed over to my shop and make a purchase or two. All proceeds will go towards making more courses.

If there’s merch missing that you would like, let me know (click this: Make Something For Me ) and I’ll try to make it for you.

neurodiverent

Awesome neurodiverent Stickers

You can buy this product or you can check out my shop of products.


About

The Author Guy

Find Me

Rob Welan <rob.welan@beareact.dev>FacebookKo-FiLinkedInMediumPatreonRSS FeedStack OverflowX

Tech In Use

Be A React Dev

© 2024 Be A React Dev. All rights reserved.