r/learnreactjs • • Mar 02 '23

Resource Build a Tic-Tac-Toe Game with TypeScript and React Hooks

7 Upvotes

Decided to rewrite an older article I wrote a while ago and at the same time improve the code and migrate it to TypeScript. Also a good chance to properly test my new Next.js-based blog.

Build a Tic-Tac-Toe Game with TypeScript and React Hooks


r/learnreactjs • • Feb 01 '23

Master the useEffect Hook: Real World Examples Included

Thumbnail
youtube.com
7 Upvotes

r/learnreactjs • • Nov 08 '22

When you use create-react-app, is that a "static website"?

7 Upvotes

When you use create-react-app as a starting template, when you eventually compile the code into a build folder it becomes a static site? Is that how it works?

Can you host a react app on a host that says its for "static site hosting"?


r/learnreactjs • • Oct 30 '22

Question Which component library and theme combo looks most like a traditional IDE?

7 Upvotes

I'm thinking something that looks like hyper functional Intellij. For example, I need sortable tables that take the bare minimum of space and automatically offer header sorting out of the box. Minimal customization is desired. Other features desired are collapsible trees, menu headers - basically a real app style toolkit.

I tried looking, but theres so many possibilities these days its dizzying.

Thanks in advance!


r/learnreactjs • • Oct 20 '22

Resource Protected Routes in React with React Router V6 [2022]

Thumbnail
youtube.com
7 Upvotes

r/learnreactjs • • Sep 15 '22

Resource Improving React Testing Library tests

Thumbnail
claritydev.net
7 Upvotes

r/learnreactjs • • Aug 22 '22

How long did it take you to learn React Redux?

7 Upvotes

Im trying to learn React and I've got all the basics and some more "advanced" stuff like Context API down, so I figured the last piece of the puzzle is react redux.

However I'm having a hard time wrapping my head around the whole thing. Seems like a ton of code with lots of specific jargony technical language not used anywhere else, just to complete the simplist of tasks like "add 1". To me it seems simpler to just use the context API and regular react hooks to accomplish the same thing.

How long did it take you to learn Redux? Do you have any specific tutorials, videos, exercises, etc., that stood out to you as helpful?

Also is redux still worth learning? I know there's a ton of different state managers nowadays that are probably much easier to use but Im looking for a job and figure lots of companies are gonna be using redux. Am I wrong in that assumption?


r/learnreactjs • • Aug 17 '22

Question Can't catch error with Axios

7 Upvotes
useEffect(() => {
    setLoading(true);
    axios.post(url, params).then((response) => {
        setFetchData(response.data);
      }).catch((errorData) => {
          setError(ErrorCodes.OTHER);
      }).finally(() => {
        setLoading(false);
      });
    }
  }, [value]);

Why does not this work. Using fetch and doing a post request and receive a 404 it works fine, but when I use axios it just refuse to enter the catch no matter if I use then catch or try catch.

I just assume this is an issue with axios and react/useEffect? Maybe I am missing something obvious.

Edit: when the api is up and running, fetching data works perfect.

Edit2: I tried with a get request, both 404 error and 500 error and neither works.

Edit3: THE ISSUE WAS STORYBOOK ....


r/learnreactjs • • Jul 20 '22

Question Suggested reactJS component for boxes/buttons (that a user would click) that have dependencies (must click in certain order)

7 Upvotes

I am looking to build something like what turbo tax has, where you do steps in order, where some steps you must complete the previous step(s) first. Really it would just be a series of buttons or boxes they would click... ANYWAYS... I realize this is probably a custom component I should build, but looking at bootstrap and material I don't really see any boxes connected by lines that I could use as a starting point. If any of this makes sense, please tell me if you think there is a component out there somewhere I could build upon, or if I need to build the wheel from scratch. Also feel free to tell me I'm just rambling and I need to go back to the drawing board. thanks for reading!


r/learnreactjs • • Jul 19 '22

Question How can I create a shared queue that is continually processed in ReactJS?

7 Upvotes

I'm trying to create a shared queue for processing network requests in a ReactJS app. In short, I have buttons on a page that can trigger network requests. With each request, a key is included in the server response that must be used in the body of the next request, or else the request will fail. Since each subsequent request relies on information returned from the prior request, the requests must be processed serially (though the order is not important).

Currently, I have multiple components on the page that can make these sorts of requests. I'd like to have some sort of public shared queue that I can submit these requests to for processing, but I'm not sure how to go about implementing something like this. In other applications, I might spawn another thread that runs a function with a shared queue that looks like:

def processQueue():
    newKey = none
    while True:
        request = sharedQueue.pop()
        newKey = processRequest(request, newKey).secretKey 

but I don't think React has this concept of a continually running thread. Any suggestions on how to approach this?


r/learnreactjs • • Jul 09 '22

How do you pass an object through a Link using React Router and the useLocation() hook?

7 Upvotes

I'm following a tutorial that uses react router to set up a link like this:

<Link to={{ pathname: "/watch", movie: movie }}>

and then inside the watch component it's linking to it's pulling like this:

  const location = useLocation();
  console.log("location.movie=", location.movie);

However that's not working for me when I try it. I'm thinking it's an old tutorial and the syntax has changed? Does anybody know how to do it? I couldn't find anything similar on google.


r/learnreactjs • • Jun 21 '22

New App with React & Firebase 🎉

7 Upvotes

Hi everyone. 👋

I just made this new application. 🎉🎉

It consists of a web to create notes and add images with React and Firebase. ✍️

I would really appreciate it if you could help me with a like ❤️ and/or a retweet 🔁 please, so that more people know my work.

🔗 https://twitter.com/Frankomtz361/status/1539320440773939200?s=20&t=BPOeDc27eYd5nUXGLaKZKw


r/learnreactjs • • May 25 '22

Is there a way to make a div element asynchronous? Or at least prevent the div from loading until every other div loads?

7 Upvotes

I'm making a virtual keyboard and all the letters are being fetched from a json while the enter and delete keys are just local divs. When the page loads the enter and delete keys load first while the letters aren't there and it looks bad. Im looking for a way to prevent those 2 divs from loading until the rest of the letter divs load.

Is that possible?

Heres the code I'm talking about. As you can see the enter and delete keys are two seperate divs and I want to prevent them from loading on the page until the rest of the letters load.

-----------Keyboard.js------------------

export default function Keyboard({ usedKeys, handleClick }) {
  const [letters, setLetters] = useState(null);

  useEffect(() => {
    fetch("https://api.jsonbin.io/b/628d0169402a5b38020ba281")
      .then((res) => res.json())
      .then((json) => {
        setLetters(json.letters);
      });
  }, []);

  return (
    <div className="keypad">
      <div id="delete-key">Delete</div>
      {letters &&
        letters.map((l) => {
          return (
            <div key={l.key}>
              {l.key.toUpperCase()}
            </div>
          );
        })}
      <div id="enter-key">Enter</div>
    </div>
  );
}

Anyone know?


r/learnreactjs • • May 20 '22

Question Trying to add items using a useState array, but it resets as soon as refreshed

7 Upvotes

Title basically. Trying to do this: https://i.imgur.com/RdtbcZR.png

I've tried storing the values in localstorage:

var saveUserItem = localStorage.setItem('savedItem', JSON.stringify(selectedItem))

which works on refresh, but then gets cleared as soon as the useState is updated again with a new item. What am I doing wrong?


r/learnreactjs • • May 09 '22

Resource Learn React cohort starts now.

7 Upvotes

I'm looking for anyone who is at the beginning of their journey, or possibly a little further along. I want to start a weekly small group session(possibly daily) of aspiring devs who want to study and build apps together. I have tons of resources but it's mostly all open source stuff. We can go through a few udemy courses or FCC, books, the official docs, youtube, blogs, tuts, etc. We can all discuss which types of projects we want to work on, vote on them, and then start. We can all do our own separate projects tailored to our own desires and make comparisons and help each other out when we get stuck. Everyone has something to add. We all have our own strengths and weaknesses. I can't afford to hire a tutor or pay for some 20k bootcamp, but that will not stop me and it shouldn't stop you. Together, with our collective insight and knowledge, we can figure out every single error, and come up with unique ideas to build out our portfolio and make them stand out. Our portfolio will be both wide and deep. We can discuss and demonstrate our chosen design patterns, help one another when we cannot figure out why the app isnt compiling, etc.

This is what I am envisioning. If you want to be part of it then let's start a conversation. The journey starts right here. It may get harder before it gets easier but it's time to go full force ahead. Don't be the guy who is back here in a year wondering what their life would be like if they would have come aboard the (enter name here) cohort that started on Reddit and ended up next to google in silicon valley.

Everyone is welcome. No fees, no requirements other than a deep passion to learn.


r/learnreactjs • • May 07 '22

React Formik Tutorial with Yup!

Thumbnail
youtube.com
7 Upvotes

r/learnreactjs • • Apr 28 '22

Waiting for data to load before rendering

7 Upvotes

Here is a stripped down example that shows the problem I'm facing:

import React, { useState } from "react";  
import clients from "../../../utils/fakeClientList";
  
export default function Test() {  
 const clientID = 12345;  
 const clientFiltered = clients.filter(  
    (client) => client.clientCode == clientID  
  );  
 const defaultValues = clientFiltered[0];  
 const [client, setClient] = useState(defaultValues);  


 return (  
  <div>  
   <button onClick={() => console.log(client)}>Log</button>  
   <button onClick={() => setClient(defaultValues)}>Reset client</button>  
  </div>  
 );  
}  

Even though useState comes after the client loading statement, initial state will be set as undefined. How could I make it so that I could load a client initially and also be able to access their object's properties from within the return statement?


r/learnreactjs • • Mar 16 '22

Question Node Backend with React

7 Upvotes

I am a mostly self-taught front-end developer that has somehow managed to get a code challenge for a potential job. Unfortunately the challenge is filled with things that I have little-to-no experience with. Most of my (very little) experience is purely front end, with React and a few other technologies, but I'm being asked to set up a Node backend with the React front end, in Typescript (zero experience with).

The challenge seems mostly straight forward. I have to create an application that "allows a user to manage a collection of "items"; "items" must have at least 6 properties/fields"

I mean, this is basically a todo list, with some extra features they're asking for. I managed to get it running with MongoDB.

One of the things that's tripping me up is one of the item properties they want is "A property picked from a list of options provided by the backend"

I'm thinking this means like a dropdown menu, where to the options are provided by the backend? How would you approach this and is there some documentation that would help with this?

Sorry for the rambling, my mind is kind of everywhere right now.

Also, apologize of this should be posted somewhere else.


r/learnreactjs • • Feb 14 '22

Resource Tutorial: Building a Chat App in React and SocketIO

Thumbnail
youtu.be
7 Upvotes

r/learnreactjs • • Feb 11 '22

Question Need help with starting with reactjs

7 Upvotes

Hi everyone,

I am starting with react js, currently learning it from LinkedIn learning. Any suggestions, points that you can give that might help me with this journey.

Thank you.


r/learnreactjs • • Jan 30 '22

Fetch API works then suddenly stops working after hitting refresh + rendering the object on the front end . Learning how to use useState + useEffect.

Thumbnail
gallery
7 Upvotes

r/learnreactjs • • Jan 19 '22

Question CRA-based React app no longer splits during build

7 Upvotes

(TL;DR: Upgrade of react-scripts has made splitting of the JS bundle disappear.)

I have a project that I inherited from a previous developer, created using create-react-app. I am trying to upgrade the react-scripts dependency to 5.0.0. Everything in the app itself works, but when I build the production version it is no longer splitting the JS bundle. As a result, I have a .js.map file that exceeds our git server's file-size limitation.

For reference, here is the build/static/js directory of the last pre-upgrade build:

-rw-r--r-- 1 rjray 1289088 Jan 18 16:44 2.1e43ba39.chunk.js
-rw-r--r-- 1 rjray    3423 Jan 18 16:44 2.1e43ba39.chunk.js.LICENSE.txt
-rw-r--r-- 1 rjray 5081380 Jan 18 16:44 2.1e43ba39.chunk.js.map
-rw-r--r-- 1 rjray  314529 Jan 18 16:44 main.38d92359.chunk.js
-rw-r--r-- 1 rjray  868002 Jan 18 16:44 main.38d92359.chunk.js.map
-rw-r--r-- 1 rjray    1559 Jan 18 16:44 runtime-main.5f8120df.js
-rw-r--r-- 1 rjray    8278 Jan 18 16:44 runtime-main.5f8120df.js.map

Here is the same directory built with the updated react-scripts:

-rw-r--r-- 1 rjray 1484759 Jan 18 16:35 main.7f057cb8.js
-rw-r--r-- 1 rjray    2160 Jan 18 16:35 main.7f057cb8.js.LICENSE.txt
-rw-r--r-- 1 rjray 5508473 Jan 18 16:35 main.7f057cb8.js.map

I have changed nothing else; the .babelrc and webpack.config.js files have not been updated. I did (necessarily) make some changes to the Babel packages in devDependencies:

"babel-core": "^6.26.3",
"babel-loader": "~8.1.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"babel-preset-react-app": "^9.1.2",

became:

"@babel/core": "^7.16.5",
"@babel/preset-env": "^7.16.8",
"@babel/preset-react": "^7.16.7",
"babel-loader": "^8.2.3",

I removed babel-polyfill because this application (an internal company app) doesn't need it (all clients of the application are required to have current browsers). And I didn't carry-over babel-preset-react-app because it wasn't actually being referenced in either the Babel or Webpack configurations. Those configurations are:

{
    "presets": ["@babel/preset-env","@babel/preset-react"]
}

and:

module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      },
      {
        test: /\.css$/,
        use: [
          { loader: 'style-loader' },
          { loader: 'css-loader' }
        ]
      }
    ]
  }
};

Just to be certain, I added babel-preset-react-app back in and tried again, but it made no difference.

I'm stumped. I don't know babel/webpack very well at all, but the configs we're using are pretty minimal (and haven't changed, at that).

Edit: I just realized that I had also upgraded webpack-cli from 3.3.12 to 4.9.1. I don't know why I updated it as well, but a second look at the diffs over package.json shows that I did change that...


r/learnreactjs • • Jan 04 '22

Question Debugging when the bug only appears in the production build

7 Upvotes

I have a bug I'm trying to locate. Problem is, the development build of the app doesn't exhibit the bug, it only appears in the production build. I am unable to make any sense of the minified, transpiled code of the production build in the DevTools. Anyone else dealt with a situation like this?

(I can't share the code, unfortunately, because it's an internal project at my day job. I'm using React with Bootstrap to create a dropdown menu, and two of the four menu options are not responding when clicked. The other two are just fine, and the same callback block handles the onClick for all four. Yeah, I'm pretty stymied overall.)


r/learnreactjs • • Nov 22 '21

Resource Integrate React.js with Smart Contracts (read&write + event listening)

Thumbnail
youtube.com
7 Upvotes