ReactJS Tic Tac Toe (FAST and MODERN Tutorial)
HTML-код
- Опубликовано: 6 июн 2024
- This video will show you one way to create a Tic Tac Toe game application using the ReactJS library.
Next recommended video: ReactJS: 3 Ways to Pass Data Between Components ( • ReactJS: 3 Ways Compon... )
Codepen: React Tic tac toe exercise and solution - codepen.io/collection/Wvoxyg
Timestamps:
0:00 Introduction
0:26 Create Square Component
0:57 Create Board Component
1:22 Display X or O letters dynamically
2:59 Calculate Game Winner
4:50 Display Player Letter During Turns
5:30 Restart Game
6:07 Refactor JSX
7:32 Outro - Please like and subscribe to help me reach others and support this channel
great visual intro, preface, and short fast explanation. well done. love it!
thank you for dropping a comment, really appreciate it! i always strive to make my videos direct to the point while doing it fast so audience will get what they came from.
Nice man. I will try to re-create this game. I'm learning bit by bit and this is a good project to cement some react concepts. Well done.
definitely. i got asked to create this game on my interview and got the job with great comp because of it.
you can use my codepen exercise to save you some time as i added react libs and style in there already so you can concentrate on the logic.
when you are very confident feel free to do everything on your own. good luck!
Thank a lot for this one! It really helped me understanding.
my pleasure Lidia!
Thanks for this!! Awesome video 💯🔥
my pleasure! expect more videos like this soon.
Tahnk you so much bro, this is the best solution i found and you explain really well! hope you upload more content like this.
you are welcome! will upload cool videos like this soon.
This is great thank you for uploading
certainly. I am in the process of creating another ReactJS video that you might interesting.
Excelente. Me encanta la manera como lo resuelves.
Gracias. Me alegro de que este vídeo te resulte útil.
you areby far the the best web dev tutorial channel i have every come across.
thanks for the sweetest comment ever! :)
Hey Just An Update I was preparing for an interview that day, and surprisingly the same question was asked, your animations and explainaions made it very easy to understand, and thanks to you i cleared that round. Keep up the good work.
@@DastageerHC congrats! I am happy to hear that my effort producing this video is fruitful to you. Please let me know if you get the role. Good luck.
You are awesome bro. thank you.
thank you for the kind words and the feedback. this channel could use them. 🎊🎉
Awesome!!!
thank you Resty! more ReactJS vids soon.
Next recommended video: ReactJS: 3 Ways to Pass Data Between Components (ruclips.net/video/e2OLRdJKnEg/видео.html)
nice one. I try to adapt this reactjs code to angular
Thank you
thanks. absolutely! practicing your craft gets us to mastery level. good luck and i appreciate the comment always 👊
Sorry your post on LinkedIn from React Jobs page. Nice video!
thank you Antonio! I’m planning on creating more valuable content like this one.
Good video bro! Upload more videos
thank you Felipe! You got it, will upload more soon. 👊👌
Thanks for the tutorial! BTW in React, it is better to treat the first argument given by useState as immutable. Therefore I would replace handleClick to:
const handleClick = (i) => {
const updatedSquares = [...squares];
updatedSquares[i] = isX ? "O" : "X";
setSquares(updatedSquares);
setX((p) => !p);
};
it is a good idea always to treat arguments as immutable in general - react or vanilla js especially if arguments are being used by other parts of app.
for this example, it is only one place and is being updated by the setSquares so i figured make this tuts as simple as possible.
@@ASoftwareEngineer clear, tnx
@@fallenIights of course, welcome
Hello sir, can you show how to make the "x" and "o" text changing color when clicked? I already try to do some edit in square and board component but I'm still confuse. Btw, nice tutorial sir
yes, it is possible. I update the Square component to add additional class where if it is clicked, i will add a class called `square--active`. That will set the background-color to something we desire. Lastly, is to add a css rule to `square--active`. You can see my implementation below.
codepen.io/angelo_jin/pen/wvNaQPw
you did all the componenets in the same file, but how do you use the click function when you use a separated files ?
you can create a function and pass that as a prop that a component can invoke. please let me know if that make sense. i cover this in one of my video
how do you implement a 'draw' functionality?
there is no draw functionality but turn functionality where each player swap turns from X to O and O to X.
Is this what you mean?
@@ASoftwareEngineer no, i mean when the game is over and nobody wins, how do you display it on the screen that there is a draw?
@@camo4970 oh i see, wasn't able to cover this edge case. An idea is to introduce another state that will track the number of turns. If the turn is 9th time and there is no winner then it is a draw. let me know if this make sense
@@ASoftwareEngineer oh thats a good idea, i will try that . Thanks
of course! 💪🤙🏻
poorly explained.
i feel bad that you felt that way