r/reactjs • u/dance2die • Aug 01 '20
Needs Help Beginner's Thread / Easy Questions (August 2020)
Previous Beginner's Threads can be found in the wiki.
Got questions about React or anything else in its ecosystem?
Stuck making progress on your app?
Ask away! Weโre a friendly bunch.
No question is too simple. ๐
Want Help with your Code?
Improve your chances by adding a minimal example with JSFiddle, CodeSandbox, or Stackblitz.
- Describe what you want it to do, and things you've tried. Don't just post big blocks of code!
- Formatting Code wiki shows how to format code in this thread.
- Pay it forward! Answer questions even if there is already an answer. Other perspectives can be helpful to beginners. Also, there's no quicker way to learn than being wrong on the Internet.
New to React?
Check out the sub's sidebar! ๐
๐ Here are great, free resources!
- Read the official Getting Started page on the docs.
- Microsoft Frontend Bootcamp
- Codecademy's React courses
- Scrimba's React Course
- FreeCodeCamp's React course
- Kent Dodd's Egghead.io course
- New to Hooks? Check out Amelia Wattenberger's Thinking in React Hooks
- and these React Hook recipes on useHooks.com by Gabe Ragland
- What other updated resources do you suggest?
Any ideas/suggestions to improve this thread - feel free to comment here!
Finally, thank you to all who post questions and those who answer them. We're a growing community and helping each other only strengthens it!
4
u/noob-no-more Aug 20 '20
What is the difference between using this:
class RenderCard extends React.Component<{and this:
const CardExamples: React.FC = () => {to create a component?
2
u/excited_learner Aug 05 '20
Need sample projects implementing design system in theme-ui or styled components
I have been looking into some theme-ui projects but most of them are using the sx property without implementating a design system. I would love some samples.
I have good knowledge of styled-components and emotion but I always have a feeling that I'm not organising my code properly. I don't know whether I should create a separate styled component or just use child selectors in css to style the child components. I don't have project structure and I feel like I'm repeating my css. I also have difficulty coming up names for styled components.
2
u/dkunal96 Aug 05 '20
Best project to implement while learning ReactJS for beginners. I have completed basic ReactJS and will be moving to Redux.
2
u/plasmaSunflower Aug 05 '20
Conceptually, how do you conditionally render an array with hooks?
2
u/AviatingFotographer Aug 18 '20
When should I use component state vs simply using document selectors? I know how to implement both but I'm not sure which one is better. For example, I wanted a modal to appear when I click a button. On one hand, I could give it the required class names conditionally based on a state and modify said state. Another way would be to select the modal using getElementById and modify classList. Is one better than the other or is it merely preference?
1
u/[deleted] Aug 05 '20
Any good project ideas with react, node, express, mongoDB. Any real life project ideas which will be meaningful?
1
u/maggiathor Aug 06 '20
Whatโs the cleanest way to check for a deep Object dependency before mapping for example. Letโs say I have something like data.settings.menu.items ?
1
u/vijayhaha Aug 08 '20
Hi, I want to use a React.js admin panel that I download from a website. My website is using WordPress, so my question is how can I sync the data from my WordPress site and admin panel that I just downloaded? Any references link that can explain my question?
1
u/cmaronchick Aug 10 '20
I implemented redux on my last project from the outset, so I did everything with functional components and maintained all updates in the store.
I am refactoring an older project that used class components in a lot of places. Many were unnecessary, and I am refactoring them accordingly,
However, in a few cases, I update the state of the component and don't really see a need to add it to the store.
Here's what I mean:
When a user signs up for my app, they need to confirm their email. There is a "Resend Confirmation" button that shows a spinner after pressing and reverts when the resend is successful.
Does it make sense to update the "resendingConfirmation" state in the store, or can I keep it in the ConfirmUser component?
What's the best practice in that case?
1
u/Fantarta Aug 10 '20 edited Aug 10 '20
how can i connect my react native app (in an emulator) with my node.js backend?everytime a try to make a post to an URL it responses with Timeout.i have a react project (the web version of the app) and i can make post or gets without any problems.i use Axios in both.
1
u/bigbluelamp Aug 10 '20
We're about to start a new reactjs project with material-ui. Can someone recommend a free up-to-date template to build off so that we don't have to start from scratch? It's a simple admin / dashboard type application with a left collapsible navigation bar.
1
u/badboyzpwns Aug 10 '20
When unit testing and integrtion testing, is it better to do it with Jest/Enzyme or React Testing library all the way?
1
u/badboyzpwns Aug 15 '20
newbie to enzyme testing. I can't seem to simulate an onclick. Why is that? is it because of Redux?
Error:
Header componenet
1
u/nyamuk91 Aug 20 '20
Is there any remote junior frontend position? I have 5 years experience in Javascript but mostly are backend. I want to restart my career and currently looking for a remote frontend position
1
u/blaterwolf Aug 23 '20
Hey guys! Just really wanna ask what's the difference between styled-components and Tailwind CSS? I'm kind of used to in Sass already but might as well learn one of the two I mentioned...
1
u/browsepooping Aug 23 '20
Is it recommended to learn CSS in React ?
3
u/monosinplata Aug 01 '20
Here's a video I made on how to create a User Registration Form with react-hook-form: https://youtu.be/mrTPrbSoAx0
2
u/xoomlist Aug 09 '20
Which layers should I write my React tests at?
For example, in an ecommerce React app, we have this breakdown of React components:
When I'm writing the test, I want to make sure that the product name is shown on the screen, so I end up copying the same test (checking that a product name renders) into four different files:
Since you often compose React components together, do you end up with lots of component test code duplication? Am I doing it right?
2
u/JustXtreme Aug 12 '20 edited Aug 12 '20
I can't seem to find a clear answer with the old google box so i'm asking here, I've been using react for a couple weeks now, working on a phone app. My question is, should i be using React Native instead?
I didn't go to in from the start because the app i was planning on building first, didn't really need access to any phone sensors.
Well, all of that is changing now and now i need access to every sensor/piece of hardware i can get access too.
Soooo, Can i access this data from Reactjs somehow? can i host an app created in reactjs to the playstore without too much hassle?
So many questions for a new wanna be app developer.
Also, any developers with extra time and open for being a developer mentor? I was once a developer with classic ASP but stepped away from the industry for some time and now i'm trying to get back into it. I've been overwhelmed with where JS has gone but super excited to catch up and get some shit created.
Also, one more thing.
I'm not even sure if i should have posted this here but it seems others have been so I guess i'm going to follow them jumping off that same bridge.
2
u/[deleted] Aug 19 '20
What's the consensus on ditching Redux in favor of the Context API?
I'm currently working on an app and I can't really imagine needing anything as a global state than my user data. The way I see it I can easily accomplish this with contexts, and if needed add one or two more contexts for other global data.
Am I being dumb? Is there something I'm not thinking about? I'm starting to get the feeling I don't actually need Redux as much as people have made me believe.
2
u/nerdchavoso Aug 26 '20
I'm using react testing library, How can I test a function inside a component? something like that, I want test
showNameandshowAge2
u/FunkyBats Aug 28 '20
Is there like a video or a thread which properly explains how to convert a class based React-redux to hooks based React-redux program.
(I know normal class to hooks switch but don't know how to do it when using redux stuff.)
2
u/WhiteKnightC Aug 29 '20
How can I reuse a component? I don't understand. Let's say I make a FancyButton in Polymer/LitElement I will make an event that says "button-pressed" then if I added it on another project I'll work the same way, how can I do this in React equivalent?
1
u/SelfManipulator Aug 02 '20 edited Aug 02 '20
Hello, I am a beginner and I have found a new tutorial to use from wesbos. Unfortunately, he didn't utilize destructuring and eslint is giving me a lot of "Must use destructuring state assignment". Does anyone know how I can turn this off? I understand what destructuring is and why it's necessary but it's giving me a hard time to follow this tutorial. I have tried putting this in my package.json file but it's not working:
"rules": {"react/destructuring-assignment": 0}
1
u/badboyzpwns Aug 03 '20
newbie about Enzyme. About shallow rendering, it shouldn't "know" the child components. But...in the docs, why does "wrapper" know about the Foo component (which is a child of MyComponent)?
1
u/TheProfessorGiant Aug 03 '20
Okay, so I am new to web dev, and I have learnt the basics, JavaScript and react till now. I am thinking about getting into mobile development, so should I learn react native cause I already know react, or I have read that flutter is better? So react native or flutter?
1
u/Josh1Josh2Josh3 Aug 03 '20 edited Aug 03 '20
Hopefully an easy one here, but I can't get my head around it.
I'm having a go building my own custom component. Here's a fiddle (it's not meant to run in browser, but should make it easier to read what I'm doing): https://jsfiddle.net/8xwtuhpa/
Basically the outer div of my component needs to be styled individually (but share some common styles) in each instance but I can't for the life of me get it down so that the className propogates correctly. The classes in question will all be contained within homeSection.module.css
If my problem isn't clear apologies, let me know what I can do to help, and thanks in advance for any help!
1
u/ShakeandBaked161 Aug 04 '20 edited Aug 04 '20
Hello All!
I am still fairly new to React so please forgive me if I made any inaccurate assumptions. I am currently working on a fairly simple app for my company. It's a very simple application that pulls a sharepoint list into a grid so users can edit quantity or stock fields and then exports a CSV file and writes the same file to a sharepoint location, maybe a bit to much preface. But the issue I am running into is with the grid itself. I am using React Data Grid by Adazzle for the grid. The main issue I am facing is that the customer needs the data to be filterable and editable and I cannot, for the life of me, find an example of this using RDS, seems to always be one or the other. Without filtering the grid works fine, but the filtering is rather important.
I understand the issue I am running into, but am still very new to react and still getting a handle on stateful applications in general. I've basically split the state between the Order.JS file and the OrderTable.js component. I'd frankly be fine having it all in one file since this is such a simple application, but I was running into issues with the filter example calling UseState in a class component was not allowed, so I attempted to break them apart but now I am running into the the issue where I filter off the top 100 rows, and update the new top row, instead of row 101 being updated in the equipment. Row 0 is, due to how the GridUpdated callback works I only have the toRow and fromRow values to work with really, and they're always the same I believe. Is it possible for me to move the OrderTable.js back into the Order.js file and get the filtering working in there? Or how and/or can I a RDG with filtering and editability.
Here is a link on stackBlitz to the code: https://stackblitz.com/edit/react-auqjer?file=Order.js It is not functional on there I will work a bit later to make that a bit better but for now the code is atleast viewable in the Order.js and OrderTable.js files if anyone has any thoughts. I feel i'm attempting something simply not possible without setting up Redux or something or the change is so simple and i'm just completely overlooking it. Or if anyone knows of an online example that demonstrates this, even in another library.
I appreciate any help and apologize for the rambling.
1
u/redditgampa Aug 06 '20
So, i have a home page and a map page. The home page has a component which displays an id and a button. The button right now directs the onclick event to the map page. I need to display another component on the map page with displays the id in the component from the homepage whose button was clicked. This component should not be rendered if map page is not routed by the onclick event that is if it is rendered by itself. How do i go about implementing this?
1
u/Likoo Aug 06 '20
Firstly, Hi :)
I'm playing around with making my first app and I ran into a problem that I can't grasp.
I'm fetching data with API and then pass it as props into my <Anime> component (that shows info about clicked show) . Inside that component I want to use some of the values in another function but they appear as undefined.
From my trying to fix the problem I noticed that, yes those values are undefined the first time component is loaded but when I go back and pick another anime to show I'm able to get all the values. I don't understand how that can happen, because even at that first time load I do get all the values rendered on page.
I hope I explained my problem in a way that somebody will be able to shed some light :D
It won't properly show but here's my fiddle in case that won't be sufficent I can provide github link
1
u/PortSpace Aug 07 '20
I have imported a big json file using
Import data from โ./my file.jsonโ;
The file contains lots of tweets and as itโs a big file rendering all the tweets took ages. Itโs not what I want to do anyway. What My aim is to analyse the content of the tweets (word counts, etc), display only tweets containing a certain word, etc. By default, itโs only display the latest 100 tweets. I have a few questions:
Thanks
1
u/embar5 Aug 07 '20
ESLint already asked me about my project framework and I marked React. Now it asks if my code runs in the Browser or Node.
I thought it ran in both? What is the correct answer?
1
u/fpuen Aug 07 '20
Anyone use formik? My
onChangehandler was expected to pass as the prophandleChange, but none of the methods (handleChange, handleBlur, handleSubmit) are working. I tried accessing the value in Formik'svalueprop, and also printing the event (e) but neither do anything.1
u/jacove Aug 07 '20
Is it bad to provide your entire app with context? I basically only use it for things like API request status & response data.
Follow up: if my context is an object and two components use and update different fields on that object, will they both re-render even when one updates a key that the other doesn't use?
1
u/Shahla9046 Aug 08 '20
https://www.reddit.com/r/reactjs/comments/i63tw1/between_these_tutorials_which_of_these_is_the/g0t7eww/
1
u/[deleted] Aug 09 '20
Is there any react mask library that supports reverse option? Like i need a mask to change depending on the number of digits. Example: (
12-34-5,1234-56-7,12345678-90-1). I already tried 'react-input-mask' and 'text-mask'.1
u/A1dam Aug 09 '20
Hello, is it common to extract all the logic of component to only one custom hook? If so, would you use it almost everywhere?
I'm thinking of using it only when the business logic of component gets quite long (3+ regular hooks with related functions).
1
u/terraforme Aug 10 '20
Hello! VERY new to React. I'm wondering how I can write React data to a database. I know I will use to Node to write the data, but other than that it's a blank. I'm interested in saving form data that I currently save in state on the submit event. I'm planning on using Airtable/Googlesheets as my database because it will be a small amount of data. Any help is appreciated.
1
u/YoungMangrove Aug 10 '20 edited Aug 10 '20
Hey guys! I'm a React beginner working on a basketball player comparison app right now, nothing too complex. Makes a call to an API to get a list of players (default 'home' is Frank Ntilikina) and then as the user enters a new search term, makes a new query to update the players state, and therefore all the players displayed on the screen. I want the functionality to click a player's small box and add them to a comparison section below. I have it right now so that there is a state of all player ID's you wish to compare and each player's box has an onClick which updates the state holding all the ID's, either appending a new one or deleting it if already selected. For some reason, this does not re render the comparison section of my page when the state is changed via updatePlayerComp(). Oddly enough, when i type anything into the search bar, that is what forces the comparisons section to render with the stand-in info I have currently. I have been looking at this for hours hoping it would be something easy but I'm at a loss, any help would be appreciated. Here is my code:
I thought whenever a state changed, any component relying on that state would re render but I'm learning this is not at all the case.
1
u/Mister_101 Aug 11 '20
I'm very new to react and am working through a course on Udemy, but working on a project on the side to try things out. I am curious about the strategy / what would be considered idiomatic in my case. Apologies for lack of specifics, but I've hit a bit of analysis paralysis and just looking for general guidance.
I have a client-side binary file (1-10MB) that holds data for several characters in a game, n bytes per character for 100+ characters. Some of those bytes are addresses to other places in the binary for things like strings. My goal is to make a character editor.
So I guess my question is, do any of these stand out as more idiomatic than the others?
My concern with the 1st approach is if the binary file might be too large. As it's my first foray into webdev, I am not sure if something ~10MB is going to be a problem, but I do want things to feel instantaneous, which is why I am leaning more towards option 3. The 2nd approach seems better than the 1st, since I feel I'm basically duplicating my data model if I parse it first, then reference fields in the props value instead of using that data model.
Since the data basically has pointers though, other parts of the binary will need to be loaded too. I think option 3 can still handle that, but it would just need to read its main character data first, then figure out which other addresses it needs to read from that and read the file again for those bytes.
I suspect the answer is that it will depend on the implementation details/requirements but any info, no matter how generic, is much appreciated!
1
u/fpuen Aug 12 '20
What happens when a React application receives a
res.redirectresponse from an Express.js back end? Say the front end also has React Router v5 and there is a route match.I have only ever sent and received json between React and Express, so a route handler like this is tough for me to understand. I'm thinking the redirect should probably be changed to
res.json, sening back a user data object.1
u/lukewarmcarrotjuice Aug 13 '20
Looking like Iโve got my first interview for a junior dev position lined up! Any body have suggestions for interview prep or resources with practice interview questions?
1
u/badboyzpwns Aug 13 '20
when testing, is it good to assume that:
unit testing is used for DOM manipulation (eg; when a page renders, check if you have a x number of <h1> in a <nav>; or when a user click a button and an animation is created, make sure you still have x number of <h1>)
integration testing is used when data is involved; such as API calls that will give you back a list of data and will want you to render it to the component.
1
u/maggiathor Aug 13 '20
hey guys, I was wondering if anybody knows how to build a automatic deployment process for cra apps on static / shared hosting. Git is enabled and I can make use of PHP, I'm using GitHub. I basically want to push to the repository and the server pulls the files and builds the app. Is this possible solely with git/php?
I kinda know that I need to use webhooks, but I haven't found a good script that I understand.
1
u/[deleted] Aug 14 '20
Hereโs a question thatโs a bit out there.
When you share a URL, on some sites like Reddit thereโs a preview window. I know how to change this with the Open Graph headers.
My question is, some sites have custom images for blog posts where the title of the post is in the image preview.
How would I begin generating this with React/NextJS? I think Iโd know how to create the images in Python, but Iโm trying to go serverless and static so the best I can do is a build-time script. Donโt think I can run Python on Vercel.
1
u/ForsakenSail Aug 14 '20
I been working with React recently. Looking to move away from WordPress development into UI/UX development with React. My question is, I built this Netflix clone app with React, is there a way to implement pure JS functionality? Like maybe menu that toggles. Or adding a sticky nav on scroll. Or is everything done through the components themselves? I'm so use to using jQuery which is where I'm coming from with this question.
1
u/nerdchavoso Aug 15 '20
React Native question - Expo video restart the video every time that I change some estate
It should change the state and either pause or play the video, but everytime that I call the function
handlePlaythe video restarted again, someone has any idea how to solve it?1
u/Verthon Aug 15 '20
React + Typescript
Hello! I have a custom Button component, however, I would like to avoid writing every property like in props, instead, it would be nice if it will be possible to inherit that props so I don't have to write
onClick={onClick}1
u/foolish_cat_warlord Aug 15 '20
what is best practice for modifying objects in a state array? example, assuming we have this component:
Is it ok to directly edit the element like this?
or would I need to make a copy of the original list and then use setList?
1
u/blaterwolf Aug 18 '20
I finished Free Code Camp's course on React and I did way beyond the course by studying class components and then jumping off to Hooks. I almost covered everything on React Basics and even learning Redux.
What do you think is the next React ecosystem I should learn?
Any advice would greatly help!
1
u/javascript_dev Aug 18 '20
Anyone use Express.js on the backend? Say an external service has redirected back to your oauth callback:
If the react app is on domain.com, how do you do a redirect, AND send json data to the react app? In my case an access and refresh token.
1
u/Hanswolebro Aug 18 '20
This might be a weird question because thereโs probably a simpler way of doing this than Iโm thinking of, but is there a way to store several components into an array using state?
Basically I want to create several card components you can cycle through using next or previous buttons, but I canโt wrap my head around doing it without having a specific index for each component. Any help is appreciated
1
u/White_Spectre Aug 19 '20
Hi everyone, I'm a student and wanted to learn React, but to be honest I'm lost, what do I need to code in React. I'm on Windows and MacOs, but i don't know if i have to make a server to host the files in local, which IDE is the best (Intellij, Vs code, etc..), what do I need to install first, and many more questions. I know thoses questions can be wierd or stupid but i would be very happy if anyone could help me.
1
u/Peechez Aug 20 '20
Here's my situation. I have a component lib package and a main app package. The component lib has a modal component that takes the children and wraps it in modal ui.
Internally, it uses react portals. The 2nd arg of
React.createPortalis the real dom element to mount the children on. This means I need to get a ref in the main app and get that into the modal component. Previously when the modal was in the main app, I just kept the ref in context and used the context hook in the modal. Obviously this doesnt work exactly since I cant import the context instance into the modal component to put into a context hook.Seems like my options are to either pass the context instance as a prop and then put the prop into the context hook in the modal, or parse the context in the main app and pass the ref to the dom element directly. I tried the former and it didn't work (probably my fault?) but I have the latter working.
Which of these are preferable? They both seem janky tbh and maybe there's a 3rd option? I'd prefer to keep the portal behaviour in the component lib for reusability
1
u/yonasismad Aug 20 '20 edited Aug 20 '20
This might be a bit specific but I have an issue with Algolia instant search. Basically, I wanna know when the Hits component is done rendering results. Is there a way to add an event listener to components?
I am a total newbie in React, and I am just trying to convert an existing application to it. Any help appreciated. - Can I know when a component I included is done rendering is what boils my question down to.
1
u/badboyzpwns Aug 20 '20
jest/enzyme question! are you supposed to use nock when doing integration tests? nock can't seem to make a network request whenever I include a <Provider> in a wrapper. Eg:
1
u/YannikSood Aug 21 '20
I have auth done through Firebase and want to integrate stripe for subscriptions. Should I just use Firebase real-time database or make a different backend?
1
u/[deleted] Aug 21 '20
Hi guys, I'm following a tutorial on this link:https://www.digitalocean.com/community/tutorials/how-to-build-a-react-to-do-app-with-react-hooks
but I'm not exactly sure how or what this code below is actually doing.
const addTodoย =ย (text)ย =>{var lovebiteย =ย "damn";const newToDosย =ย [...todos,ย {text}ย ];setTodos(newToDos);}From what I understood, the
"...todos"is supposed to expand the array itself, but if I tried adding any string to the second argument, it doesn't seem to add to the array. Am I misunderstanding something?1
u/[deleted] Aug 21 '20
How can I check the origin of HTTP requests made from my create-react-app live dev server?
I built a backend and want to add the origin of the dev server I'm working on to the cors config, so that it accepts requests with credentials. However, I have no idea how to check the origin of requests made from my create-react-app dev server on http://localhost:3000/. I tried adding my IP address but it's not being accepted as valid.
1
u/badboyzpwns Aug 22 '20
I played with testing with both enzyme and RTL; I understand the idea behind their designs for both; but at the end of the day, they achieve the same goal, to do testing. React even advocates RTL as a testing library; is it safe to say that it's completely okay to "disregard" enzyme forever? RTL seems much simpler to implement, so I don't see a benefit at all with Enzyme.
1
u/real_satoru_iwata Aug 22 '20
Hi! I have an array that I am trying to shuffle on initial load, and onClick. My functions seem to be working but arent visible unless there is a rerender.
I'm trying to resolve 2 issues:
CodeSandbox
1
u/badboyzpwns Aug 24 '20
In react testing library, how do you test a component that "switches" class properties?
I have this so far:
1
u/javascript_dev Aug 24 '20 edited Aug 24 '20
react router v5. I sometimes mix up the url vs path. Also match vs location.
if i wanted to listen for a route click on, say,
/portfolio/item1, what is the best option?I lean towards
location.pathName. match seems to be different; in the above example its value was/which seems hard to square.1
u/jan_sv Aug 24 '20
I think I have a very common problem. I have a couple of more or less static sites (blog, about page, landing page) and a dynamic app that is behind a login wall.
How do I combine the static pages with a react app?
I am especially worried about the login part. The user should be able to fill out the login form on the static landing page and then get transferred to the dynamic react app.
Do I need NextJS?
Does Gatsby + React work?
What would you recommend and why?
1
u/badboyzpwns Aug 25 '20
in react testing library, how do you get a text that has spaces?
I have
and I did:
1
u/AviatingFotographer Aug 25 '20
Render props and custom hooks both seem to have the goal of separating state from UI rendering. From my understanding, render props removes the UI and keeps the logic whereas hooks removes the logic but keeps the UI. Is one better than the other and when should I use what?
1
u/sumedh0803 Aug 26 '20
I'm new to React, and just now learnt about portals. Ok, i understand that portals are used if want to render some components outside of the root element. What advantage or practical use does this have? Also, cant I make a .js file similar to App.js (say App_new.js), and a sibling to the root element in index.js (say div#root-new), and render the App_new component inside div#root-new using ReactDOM.render()? In this method, my index.js has 2 ReactDOM.render) This approach is working perfectly, so why should use React portals at all?
1
u/worthy_sloth Aug 26 '20 edited Aug 26 '20
I'm on to my second 'official' app. I'm building a web app to track a hockey game stats. I have a list of players. Each player is a <Player penalties={0} .../> with some more props. The list is generated using map and is a component in of itself.
On the <TeamList /> component, I have a button that I want to click to add a penalty to a selected player. How do I go about changing the prop.penalties of the SELECTED player ? (increasing it by 1)
PlayerList
Player
App
EDIT: Basically, I want to make the Player.penalties prop dynamic, but I want it to change Player by Player (so they don't all have the same amount of penalties)
1
u/sidmas8086 Aug 26 '20
Where should i do api calls while using redux?
In front class component or use redux-thunk and use dispatch to bring data to front.
1
u/stfuandkissmyturtle Aug 26 '20
Hi, so I've recently learn some base react. I'm no way an expert but I can make API calls and some simple apps.
My dad due to covid can no longer attend mass, and he has to watch them live on YouTube, but he finds the app difficult navigate on. I was wondering if there's a way I can make a youtube player that only shows live videos by default. This way all he has to do is type keywords like "church" and he'll get a bunch of videos. He can then even watch some news.
I also want add features like live videos that will go live in less than 30 mins or 15 mins etc.
I'm not really confident on how to go about this and how or which api to use.
1
u/badboyzpwns Aug 26 '20
newbie question about lifecycles.
I have a component that creates a "Review" <div> after a button is clicked. This will update my component store and renders a the new size of "Review" <div>. But I want to call executeScroll() after all the <div> renders.
I tried doing it with componentDidUpdate() but it wasn't a success
1
u/pramish22 Aug 27 '20
Hello guys, I created a website using React. But whenever I open that site from a mobile or a tablet, it shows a whitespace on the right and bottom side. What is causing this?
1
u/[deleted] Aug 27 '20
I have a question about installing packages and dependencies of those packages.
Say I install
react-springin my project. I then also install a package that depends onreact-spring. In my final build bundle, will the two react spring dependencies be merged into one or will they be kept separate?Would that only happen if the two versions of the dependency were different?
1
u/Dystriel Aug 27 '20
Hey guys! Just started learning React very recently and I'm seeing all these discussions on Hooks VS Classes and the direction React seems to be going forward with hooks. Honestly I find classes to be really confusing especially with multiple components, compared to using hooks with functions.
Would like to know if I should jump straight into coding with functions and hooks or learn to code with classes first before experimenting with hooks in my code?
1
u/liveinspring2092 Aug 27 '20
Hi, guys, I am finished the course on Udemy for React JS. I am trying to directly edit the element from a template. I followed several tuts on Youtube, However, my terminal code failed which is different from the video. I got following errors in termimal.CouldI know how to solve it ?
> react-scripts start
sh: react-scripts: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! material-dashboard-react@1.9.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the material-dashboard-react@1.9.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/yinmeishen/.npm/_logs/2020-08-27T15_46_04_962Z-debug.log
[yinmeishendeMacBook-Pro:~/Downloads/material-dashboard-react-master]
1
u/AviatingFotographer Aug 28 '20
When does code not in anything run? For example how does this:
Differ from this:
1
u/MacauNotMacao Aug 28 '20
Hi, all. I'm a beginner to React and writing a simple project to practice my React skills. I've met a problem with pass data to other components.
For example, I have 3 components:
Parent_A -->Child_A
Parent_B
My data is saved as states in Parent A and I can pass data from Parent A to Child A. What I want to do is when Child A is clicked, passes some data to Parent B and show the data on Parent B component. How could I do it?
1
u/fctc Aug 28 '20 edited Aug 29 '20
I'm trying to import a set of images, then tell the loading screen that it is okay for the user to continue. A spinner will be displayed, then a 'continue' button will replace it after the images load. myFunction seems to be stuck changing old state, and leaving the spinner up forever. I kind of expected that, at this point, but can't figure out how I should be doing it.
Main function with reducer:
The Menu component just dispatches to the reducer, no problems there.
Loading component:
myFunction as seen in the reducer:
I can see that this won't work for a couple reasons, but everything I've tried has had the same result. Thank you for taking a look.
https://ProtoPla.net to see what I'm doing, currently there is a canvas loading screen that works okay, but I'd like to use the react loading screen I've been working on.
1
u/stfuandkissmyturtle Aug 29 '20
Can anyone explain what Im doing wrong ?
0 info it worked if it ends with ok1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]2 info using npm@6.14.63 info using node@v10.22.04 verbose config Skipping project config: /home/bludshed/.npmrc. (matches userconfig)5 verbose stack Error: ENOENT: no such file or directory, open '/home/bludshed/package.json'6 verbose cwd /home/bludshed/youtubeLiveK7 verbose Linux 5.4.0-42-generic8 verbose argv "/usr/bin/node" "/usr/bin/npm" "start"9 verbose node v10.22.010 verbose npm v6.14.611 error code ENOENT12 error syscall open13 error path /home/bludshed/package.json14 error errno -215 error enoent ENOENT: no such file or directory, open '/home/bludshed/package.json'16 error enoent This is related to npm not being able to find a file.17 verbose exit [ -2, true ]1
u/[deleted] Aug 29 '20
I have a project structure question concering the React Jira clone project.
Specifically I am wondering what is the purpose of the browserHistory.js file. All of it's code is:
This is then simply imported into the Routes.jsx file and used.
My question is why have this imported into a single file only to then import it again? Why not just do
import { createBrowserHistory } from'history';directly inside the Routes.jsx file?1
u/terraforme Aug 29 '20
This is driving me bonkers. I have a child component with a menu where you can click a switch. I listen for the click and pass it to the parent component, where I change the state based on the click. I want to toggle the state here: 1 click ==> true, next click ==> false, next click ==> true... etc. The issue is: the click only changes the state once! (The first time).
Any suggestions? I can provide code.
1
u/wretchedCoder Aug 29 '20
I am trying to make a React App SPA that pulls info from a Jeopardy API and I need it to take user input and compare it to the Data pulled, as well as adding or subtracting the score for each question pulled. I have something like:
if {userinput-convert to lowercase} = this.data
then userscore = state/userscore + this.data.points
else
userscore - this.data.points
I have worked with React and Javascript before but React App is new to me and I'm still getting the hang of everything. any suggestions? the syntax is still alien to me, but I'm trying my best. any help would be appreciated.
1
u/webdevkoala Aug 29 '20
Hello guys. I have been thinking about a solution for two days :(. Could you please tell me how to build a container with hover effect from https://hotelicon.com website? I mean I want a container with three columns, when you hover over any picture it takes up all three columns.
1
u/fpuen Aug 30 '20
When debugging a React.js app, do you guys attach a debugger to the webpack process, or something else? thanks
1
u/RohanCR797 Aug 31 '20
Good resources(Books/Youtube playlists or channels/Courses) for learning ReactJS and React Native??
1
u/[deleted] Aug 31 '20
Where does prevNumber come from in this function?
I thought maybe useState returned it as a part of the array. And I was using object destructuring to put it in this function. But then I read online that useState only returns 2 values. And that the variable can be named anything. So how am I accessing it and how does it represent the previous value of number if I'm the one initializing it?
1
u/trevdak2 Aug 31 '20
I'm looking into testing-library for a spike, and either I'm completely confused or this library is completely worthless.
I wanted to write a unit test for something simple. We have a component that, given its parameters, returns different components... Ok, Warning, or Error.
In enzyme, this is easy. shallow() the component with various params, see whether I get back a Ok, Warning, or Error. In testing library.... I need to use a regex to look for localized text that's several dozen components down the tree? How in the heck is this an acceptable way of testing? Seems like there's no way to change code with this that won't cause cascading failures through all sorts of unrelated tests
What am I missing?
1
u/fpuen Aug 31 '20
Is there any simple solution to transitioning <Route /> components?
Problem I see is they need time to come in and out before the state flips to the next <Route />
1
u/[deleted] Aug 31 '20
Hello!
I am building my first real project with React (you know after a few simple things). Anyways, I am building it with a Java backend with a Spring MCV architecture with React being my V.
I am using maven and was wondering if anyone had any advice on what dependencies I might need from start.spring.io
1
u/Zeroays Sep 01 '20
Hi, I'm a React Beginner trying to build a toy project. I started with Connect 4, but am having trouble with the "Column Selection" Feature. It calculates which column the Piece should appear above, based on Mouse's X/Y Offset relative to the selection container. The formula is on line 68, of the "ColumnSelection" Class.
The Feature sort of works, but there is a jitter in the Piece Positioning. When moving the Piece, it zips back and forth to/from Column 1 (far left). I am not sure if it is a rendering or calculating issue (or both).
Any help is greatly appreciated :)
Link: https://codesandbox.io/s/solitary-meadow-9cw5y?file=/src/App.js:1625-1688
1
u/javascript_dev Sep 02 '20
Framer Motion question. Can anyone tell why
durationis being ignored? The default setting seems to apply, and it's too fast:1
u/[deleted] Sep 02 '20
If anyone could help me with this :)
https://www.reddit.com/r/learnprogramming/comments/ildpy7/javascript_react_in_useeffect_can_i_change_the/
1
u/[deleted] Aug 02 '20
Recoil is better than Redux. Thoughts?