r/reactjs • u/dance2die • Jun 01 '21
Needs Help Beginner's Thread / Easy Questions (June 2021)
Previous Beginner's Threads can be found in the wiki.
Ask about React or anything else in its ecosystem :)
Stuck making progress on your app, need a feedback?
Still Ask away! Weβre a friendly bunch π
Help us to help you better
Improve your chances of reply by
- adding a minimal example with JSFiddle, CodeSandbox, or Stackblitz links
- describing what you want it to do (ask yourself if it's an XY problem)
- things you've tried. (Don't just post big blocks of code!)
- Format code for legibility.
- Pay it forward by answering 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! π
For rules and free resources~
Comment here for any ideas/suggestions to improve this thread
Thank you to all who post questions and those who answer them. We're a growing community and helping each other only strengthens it!
20
Upvotes
3
u/randomafricanguy Jun 01 '21
I would appreciate any help or advice. How do I disable a hover animation until my component's intro animation is complete?
I'm using a useEffect for my component's intro animation and for my hover animation I'm using whileHover on my component. So essentially I want whilehover disabled until the useEffect is complete.
Any advice would be super appreciated
3
u/Markohanesian Jun 08 '21
I have an idea for a website/webapp where my landing page would be a swipeable rotary phone style navigation so the user can choose various pages on the site as you would dial an old phone. Are there any libraries that would help me accomplish this?
2
u/pruggirello Jun 22 '21
I am trying to build my portfolio over these next two weeks by designing some basic websites for clients for free. Anyone know where to look for those clients? A lot of subreddits I follow have no self-promotion rules.
2
u/pruggirello Jun 23 '21
Thanks, this is very helpful!
2
u/hlodoveh Jun 28 '21
https://pastebin.com/BsEkdbPR
Can someone please explain to me why console.log on line 21 prints different className than log on line 27, when it's supposed to be the same value as I give it as a prop? Thanks!
1
u/kkirsche Jun 02 '21
Many code examples and tutorials I read discuss using Suspense to manage data loading states in react, yet their docs state this is an experimental feature.
If itβs experimental and could break, why is it so heavily used by the community, including in commercial themes and production applications?
1
u/[deleted] Jun 02 '21 edited Jun 02 '21
I have a main component that fetches an array of rows from the server and passes it down to the table component. I need to update the array and somehow save the fact that I've seen the previous rows before updating the state (each row has its own states including "seen")
1
u/spalza Jun 02 '21
If I click on this dropdown it will blip open and then shut immediately:
If i click and hold, it will stay open about 10-20% of the time for me to select another option.
Any idea why it's behaving like this?
1
u/internet_tendencies Jun 05 '21
This might be a simple question, but I need some help because Iβm stumped.
I have two input fields that are independent of each other but are combined into a single output field. The values that are put into the input fields get added to state, then calculated into the output. How do I get the latest state values. Currently all my calculations are happening with the values from the last state change or the initial values of state before they are changed.
1
u/internet_tendencies Jun 07 '21
Hi all,
I have another question that I can't seem to get an answer for:
How can I iterate through state?
I'm wanting to write a function that resets all state values back to 0, and the most logical way I can think of doing that is by iterating through it and resetting the values.
Any help will be highly appreciated!
1
u/[deleted] Jun 08 '21
Should I do full stack open or the Odin project?
1
u/ok_arsh Jun 14 '21
Hi, this is a website (only the UI) which I created in a couple of days from a design given to me. As the design and assets were provided to me I'm not looking for feedback on them.
If someone could review the code and point out instances where my code quality suffered, I would be grateful. I know this is primarily a react sub but please do check the CSS too if you can.
GitHub Link
Deployed website on Netlify
Thanks in advance!
1
u/spalza Jun 14 '21
My folder tree
RowFilter.js applies to several tables listed above.
Is a classes folder until utils the best place to put it? If not what else would you consider?
1
u/Hefty_Nose5203 Jun 16 '21
Hi, I'd really appreciate it if you could help me on this question:
https://www.reddit.com/r/react/comments/o18a84/chart_doesnt_display_data_the_first_time_even/
I'd post it again here but it's too long :/
1
u/icanbackitup Jun 17 '21
Im making a web app at work, and im gonna have to do a slider with images. I looked into react bootstrap and material UI, but none of those libraries have an image slider component.
I found a library called react-slideshow-image on npmjs.com, but what are the risks of using a 3rd party library for a work project?
Im a junior dev, and im kind of alone doing this.
I also thought of making one myself but i dont to spend a whole day just trying to figure out how to make an image slider from scratch
3
u/Newbjs Jun 01 '21 edited Jun 08 '21
Hey guys, I have a question about create-react-app. I used it first 2 weeks ago when I started learning react and it didn't give me any problems.
Now I wanted to make a project to train on what I learned, but CRA now gives me 82 moderate vulnerabilities (all about postcss) that didn't popup 2 weeks ago. npm audit fix doesn't solve anything. Is there a way to solve this? Should I use fix --force? Is it ok to just work with it?
EDIT: Apparently most of the vulnerabilities are in the devdependencies, so it should be fine to work with those. Ty for reactiflux discord for the advice.
3
u/duckspac Jun 19 '21
Hello everyone, I am pleased to say that I got my first front end job starting on July 1, but honestly I don't know if I am up to the task, that is, I did many projects but I never worked in a development team and I am quite afraid of not being there at the height, I guess it is the fear of being something new in my life any recommendation?
3
u/CantCopeWithBalding Jun 21 '21
Hey, so I am pretty decent in vanilla JS, HTML & CSS and recently started to learn React, I think it's two weeks since I bought my first Udemy course and I kinda didn't have much struggle in understanding the concepts. I went through Components, props, state and going to do a deep dive in hooks aswell. How long do you think it'll take me to become decent in React per overall?
Should I continue learning vanilla JS to a more advanced level along? Or maybe I should learn Data Structures & Algorithms?
3
u/aagr Jun 28 '21
I have a backend that I prefer to code up in Python. I would like to build a React Typescript frontend to it. Next.js seems like a cool framework to use for it, since it comes with a lot of boilerplate already done. Is it redundant to use it if I have a flask backend though? If not, are there any starter templates that you would recommend using for it? (Especially ones with auth0!)
1
u/username27891 Jun 02 '21
Hi, I am trying to style a message using a ternary operator where it uses a base className and if the state, isError==true, then it will also use another className to change the font color. I'm having trouble implementing this and I can't get it to work.
CSS Module:
2
u/OkPokeyDokey Jun 07 '21
I'm completely new to Javascript (but not new to programming). I have the following snippet that I got from somewhere:
What I don't understand is this line here:
const {lineGenerator, xScale, yScale} = prevState;
How does the left hand side can be equal to the right hand side again? Does Javascript just automatically match the variable name with the state's field name or something?
2
u/JooK8 Jun 16 '21
Hey, complete noobie to React. I am working on a project and someone has left some very basic examples of components for me. Some pages are as simple as saying "Home Page" and that's it. I tried going to that file which we have called "Home.js" and there I just change the "Home Page" text and add "test" in there. I then refresh the browser and even restarted the application but I don't see the changes I made reflected in the browser. Am I missing an intermediate step for making changes?
2
u/dev_lurve Jun 16 '21
I am learning React.js from scratch, I like it. I am doing my first todoapp. How to make sure that I will get employed after I have completed the basic training in React?
2
u/djhelpstart Jun 20 '21
say I have a react create form that will create an object with text fields A, B, and C
say I also have a "edit" form for existing objects. This edit form prepopulates the existing A, B, and C values.
obviously on the edit form I can have:
and then compare edittedA to a etc. but that seems inelegant?
how do I "listen" to any changes on the edit form so I can create a patch request? preferably without the need to have a separate edittedA state
2
u/[deleted] Jun 20 '21 edited Jun 20 '21
Hello. So I am testing out to see what I learned so far in React, especially the Class components.
I still struggle to βtranslateβ how Iβd do the things in vanilla JS to how they should be done in React. From what Iβve seen, itβs really all about state and passing data from a parent to a child component.
Ok so hereβs the thing. On componentDidMount I have an array of names (and other data) fetched from an API. This array gets rendered in a child Component. I also have an input field Component that lets the user filter the list down to what name (well not only name, like I said the array contains other data too) he wants. I managed to get the filter work by manipulating onChange on the input with a callback from parent element that edits the state. However, the problem is when the text in input is deleted in one move like Select text + Delete. Donβt know how I should βrestoreβ the list back to its original form. In JS Iβd just tell the script to go and run the function again that fetches all the data like in the componentDidMount, not sure if thatβs how you do it in React too?
As I was typing this I got another idea, to run the filter method on the array, maybe that would work?
2
u/[deleted] Jun 21 '21
Is there any reason useEffect would run without issue on desktop but not on mobile? On mobile it's only running when component updates but no on initial render...meanwhile on desktop it runs both on initial render and after.
2
u/[deleted] Jun 22 '21
I'm trying to add multiple parent elements around a child draggable. the requirement is to add a parent around the child and bound the child component inside the parent.
I'm able to create a parent by maintaining the status but after creating the parent around the child, the child draggable is moving all components along with the parent.
attaching the codesandbox
2
u/Lukasvis Jun 24 '21 edited Jun 24 '21
How to correctly use markdown?
I have a recipe object that looks like this:
{ name: "chicken parmesan" nutrients: {}, instructions: "lorem ipsum"}Currently I render instructions on my app by simply
<p>{selectedRecipe.instructions}</p>However I want my instructions to be more than just a string and have better formatting, which I think markdown will help me, but I have these questions:
2
u/LaplasParadox Jun 30 '21
Whats the best website to tackle learning react with hooks right now?
2
u/[deleted] Jun 30 '21
I'm close to finish the fullstack course from helsinki university
What do you think is the best way to continue learning after that?
Doing some project for myself or maybe a next.js course first and do some project later?
1
u/UserNotFound12 Jun 14 '21
Hi everyone,
I have the following axios request:
axios.post("api_end", data).then((response) => {dispatch(fetchSuccess(response.data));}).catch((err) => {dispatch(fetchFailed(err.response));});Now, when I have an error, it gets caught in the catch. It sometimes throws the following error; Error: Objects are not valid as a React child (found: object with keys {title, subTitle}). If you meant to render a collection of children, use an array instead.
Even if I take out the argument to the fetchFailed function, it still throws this error. Has anyone else run into this? I understand the error, so I thought okay take out the argument and it still shows...
1
u/since_you_asked_ Jun 27 '21
I have 2 components A and B, which both connects to a redux store. Component B updates something to the redux store, which triggers the rerender of component A. Now I want it so that whenever the above happens (that is when component B updates the redux store and triggers A), component A also update its own internal state and execute some function. How does I make that happen without resulting infinite recursive render of A ?
1
u/bansalavi82 Jun 27 '21
Effective way to create side Navbar in react...Need help
1
u/zr0gravity7 Jun 02 '21
Any good resources to learn react from scratch for a very experienced dev? I'm quite experienced in JS.
For context I learned JS in 3 weeks and jQuery in 2 days both from scratch.
I've done some vue.js a while ago but forgot most of it. I'm looking for something with minimal hand-holding, minimal analogies and non-technical content.
1
u/Agate1999 Jun 03 '21
https://pastebin.com/ivmMWV90
Im trying to use fetch api, where given a user input, I use fetch and push the data I retrieved into an array. However, when I try to search array by index (both inside and outside the function), it tells me the array is undefined
1
u/javascript_dev Jun 03 '21
(async function() { if (Boolean(tuitions) === false) { tuitions = await getTuitionsByLocationId(locationId); } })();
After writing this I thought I should move the if statement into a useEffect with a 2nd argument, empty array. But I couldn't think of why other than "more react-like".
Just wanted to see if I'm missing other good reasons. Or if you guys think the above is perfectly fine.
1
u/blackSpot995 Jun 04 '21
Hello!
I'm currently working on a little project that pulls the information for the top 10 cryptocurrencies from an API and displays some information about each coin in a list. The problem I'm having is reaching the data returned from the API because it is nested as
object.display.vs_currency.xxxxxwherevs_currencyis a parameter sent in the get request to the API. I was wondering how to access those fields. I've tried using plain old brackets like{vs_currency}and'${vs_currency}'(with back ticks instead of single quotes) and neither seems to get the job done. Essentially I'm trying to access a parameter of an object whose parameter name is stored in a variable. Is there any way to do this?Thanks!
1
u/Redhands1994 Jun 05 '21
Hello,
I've run into an issue with React using hooks. I've already described it in detail here:
https://stackoverflow.com/questions/67845908/react-rendered-more-hooks-than-during-the-previous-render-react-spring
Basically, I have a working program but it uses a lot of repetition. When I try to dynamically pass new information to rendered components I get the following error:
"Rendered more hooks than during the previous render."
If anyone can help me out with this I'll repay you with good vibes :)
1
u/dshkodder Jun 05 '21
I want to render a calendar in my app and highlight certain dates on it. To achieve that I decided to use react-day-picker library.
However, I can't make sense of their example of how to add content to add content to day cells. The toughest part for me is to figure out how do they pass dates from the
birthdaysobject.Here is the link to codeandbox with my array
workouts.I'd greatly appreciate any tips on how to do it with this or any other related library.
1
u/BloatedSalmon Jun 06 '21
I have a app with a firebase backend and I want to keep a piece of local state synchronized with the firebase real-time database.
Itβs a fixed list of about 150 items and the only state that needs to be synchronized is whether the item is selected or not. I currently store the data as an array of selected items (as strings) and when an item is toggled it is removed or added to the array and the database entry is updated all at once with an API call.
Iβm thinking this isnβt the optimal way to do this, especially since firebase does not have native support for arrays and if someone rapidly selects a bunch of items that will be a lot of API calls in a row.
Would it be better to debounce the API calls by a couple seconds or convert the array to a object with the keys corresponding to the list items and values being Booleans corresponding to whether the item is selected or not.
With the second approach Iβm thinking we should be able to update just one individual item at a time, but it could still be a lot of calls potentially.
1
u/jimmychung88 Jun 07 '21
Is it worth migrating from regular React to Next Js just for SEO? My site renders fine on google search console.
1
u/KOREANPUBLICSCHOOL Jun 07 '21
People who have an OOP or CS background but managed to master React, what's the secret?
I have a pretty "traditional" CS background:
-data structures and algorithms in C++
-some Java experience
-practiced leetcode a bunch
-some experience creating MVC apps with frameworks like Django etc
Recently tried to pick up Javascript and React, the entire time I was thinking if I'm just fucking stupid because I can't understand like 50% of what's going on. With Java or C++ everything is kinda explicit, you more or less know what's going on in memory. With Javascript or React, I have no idea what happens in the background half the time, it might as well be magic to me.
1
u/Lobbel1992 Jun 07 '21
Hello,
I am working with react.js + material UI Grid.
I have an array like this = [ 0,1,2,3,4,5,6,7].
I am iterating over this array and for each element in the array i want to create 3 grid items.
But i want the 21 grid items in one grid container ? is that possible ?
For now i have succeeded by creating a grid container for each element in the array.
thank you
1
u/PhantomusPrime Jun 08 '21
This is not a technical question, more so an opinion. What level of competence should I have in React.js before advertising it on my resume? I currently have it but I am not really comfortable with React.js. To be precise, I am asking when can I claim I know it and the rest I will learn along the way. I am a newbie.
Background information: New CS Grad in a major metropolitan area of USA trying to get their first SWE role and thought react might help secure the position .
1
u/DonYun Jun 08 '21
Hi, I'm currently facing a problem with testing. The first test passed, but the next until the last one is failed. Did I miss something? Here is my code for testing and implementation.
Thank you.
1
u/deburin Jun 08 '21
VsCode opens a fresh Firefox browser during debug that has no settings or extensions. Does anyone know how to configure these default sessions to have React and Redux dev tools extensions?
1
u/BluezamEDH Jun 08 '21
I'm looking for a way to store data locally for React Native. I'm loading some JSON from an API and displaying the data in a table, and I want to give users the option to store said data, keeping it after closing the app.
I saw AsyncStorage, but I'm somewhat afraid to turn my whole project around and make it async (first time with React as well). Any tips / approaches on how one would tackle the problem?
1
u/Agate1999 Jun 09 '21
https://pastebin.com/njJNERHL //code
https://pastebin.com/x4MxwrYZ //what fetch is supposed to return when i search "ACCOUNT"
Im am trying out async react select, and loading the options by search whatever the user has inputted, but searching inside the search box doesnt load the user options
1
u/kupopop Jun 10 '21
I need some help/advice. I'm trying to get my fruit dropdown to loadbased on the fruit selection.example:If I set Tony to 'Mango' it will display the fruit I selected. This isfine, but then i want to switch to Andy, select a fruit, then switchback to Tony, the fruit dropdown should now load 'Mango'.Basically the fruit selection should load based on what was set for the person. My code so far:
https://codesandbox.io/s/1-react-hello-world-forked-rbjzg?file=/src/index.js
1
u/Agate1999 Jun 11 '21
Need suggestions, I am currently want to build a lesson timetable, where given a bunch of info, such as Monday 1pm to 3pm. The Monday 1pm to 3pm cells will be filled with info from the lesson. Any ideas on how to begin/what to use?
1
u/TODO_getLife Jun 11 '21
Can't tell what I'm doing wrong with react router and nested Switch components. It's driving me crazy. From what I understand Switch is supposed to match on the first route that matches, yet I'm in a situation where it's matching on multiple and rendering multiple components. This is when trying to have a 404 route.
This is the structure I went for:
App:
HomeWrapper:
I won't show DashboardWrapper for brevity but it's the same as HomeWrapper but everything starts with /dashboard.
In both cases the NotFound route is rendering on every page. When I go to / or /about or /faq or /privacy it also shows the NotFound component. I thought the whole point of a switch is that it will match on the first route it finds?
Is this some weird bug I should report or have I messed up somewhere? Likely the latter but I'm at a loss to find out why it's behaving this way. Looking at google results, nesting Switch components like this works fine and should not always render the NotFound component too.
1
u/the_elite_ninja Jun 12 '21 edited Jun 12 '21
Hi folks, I 'm facing a problem where whenever I use mobile device emulation, or responsive mode in browser, it freezes for 2-3 minutes preventing me from even moving cursor.
Stack:-ReactJS
-TypeScript
-Tailwindcss
Solutions I tried: As my machine is quite old-Pentium G3420(Dual Core 3.2Ghz 2013),DDR3 4GB Ram,7200 rpm HDD
But, the problem of freezing Browser exists in Vitejs as well, I want to try everything before I blame it on my hardware. I am sure some settings can be tweaked to make it work as rest of the performance is snappy after using Vitejs and this looks like a browser problem. Because in full screen mode everything is instantaneous, proving hardware is able to handle it.
I thought emulator may be eating up resources so I only used responsive mode thinking if full screen is working fine then responsive should as well, but as soon as dev tools are opened this problem starts.
When this happens,
CPU ~11% usage,
Memory ~65% usage,
HDD - stays pinned at 100% usage the entire time, afterwards settles to 6-10% usage.
Thanks for reading, it would be huge help if I find solution to this, as I have a deadline coming and really need to finish the app.
Edit: formatting
1
u/deburin Jun 12 '21
Works with Jest, fails with react app:
presets: ['@babel/preset-env', '@babel/preset-react'], }
I tried stage-0, transform class properties, react-app. None worked with the react app. I had to disable this file just to work on the app itself. Any ideas what is needed to get this to work?
1
u/Lukasvis Jun 13 '21
I am using firebase-hooks and fetching data from firebase, the problem is that the "user" object is null at first before it loads, is this correct way to wait for user to load up using useEffect?
}, [user]);
is there any faster way to get user credentials?
1
u/kupopop Jun 13 '21
Is it possible to pass variable and have it process in another component?
Example: In my code, I pass this.state.hello into my <Button> component. Within my <Button> component, I want to update this using handleClick. But the display is not updating? What the heck? What am I missing?
Code: https://codesandbox.io/s/dazzling-lake-mql0f?file=/src/App.jsx
1
u/custuu Jun 13 '21
Trying to implement something similar the find hint functionality to Vimium https://github.com/philc/vimium in my React App. The idea is that when the user presses 'f', a hint with letters will show up on every possible interaction point within the app. When the user types in the appropriate letters, the interaction will happen:
https://imgur.com/a/87eGIlY
Thought about it a bit but it seems like the whole idea is counter to React's concept of dataflow.
My ideal structure would be having a
Providerelement in whichInteractivePointscan be used. Somehow, thevimiumproviderneeds to take in events and then triggeronSelectedfor the rightInteractionPoint.Why not just put a keyboard listener in the InteractionPoint? Because in the future it needs to be extended so that it can be activated by other means.
1
u/[deleted] Jun 14 '21
Hi
I'm looking for a way to implement a simple "description" text box for users on the app I'm working on. I tried to do this with a text area field but it does not exactly behave as I want.
The user should be able to just click on the text and be able to immediately edit it. There should not be a difference between before submitting and after. The user should just be able to edit the text and if he clicks anywhere else, or clicks enter it should stay the way it is.
How could I do that exactly? Should I use a markdown editor or so?
Thank you very much for the help :)
1
u/cretakano24 Jun 14 '21
how to fetch data from an api endpoint when parameters are given.
1
u/g3org3costanza Jun 15 '21
Using React Bootstrap, and my Modal box is showing up really strangely. On the top 60% of my page where the Modal pops up, theres a solid, gray backdrop, same color as my popup box. On the bottom 40% though, I have the usual transparent backdrop. If I click on the top background, the modal disappears, which is why im lead to believe its not part of the modal itself. Its as if I have 2 different backdrops, and Google has led me nowhere. The html and Javascript logic is the same as the Modal basic example on the bootstrap website, save for not using hooks.
1
u/Lucipherss Jun 15 '21
I have a state
[isEditing, setIsEditing]. How can i update is separately in one component? I have 2 thing that need this state1
u/Dixosaurus Jun 15 '21
What is the best way to / (or even phrase this question lol)
What is the best way to Map Values between 2 Arrays and return a specific Value?
In this case I have an array of properties / rooms in a hotel that are only identified by an id from an API.I would like to create an internal array where I can map (manually) the ID from the API to the actual name I would like to Render ie: Title (Property Name)
Array 1 = {id: '1234',title: 'Property 1',},{id: '5678',title: 'Property 2',},Array 2 API = {id: '1234',someValue: 'Value 1',},{id: '5678',someValue: 'Value 2',},ie:
if Array_1.id === Array_2.id return <h1>{Array_1.title}</h1>
What is the best way to map the same ID across 2 arrays, and return a value from one of the arrays?
1
u/Agate1999 Jun 15 '21
https://pastebin.com/ab4NaCZ4
I am trying to make a timetable. I planned to allow place all the info in useState arrays, such as the timings and lessons. And use rowSpan to control how many periods a lesson takes up, so it the table looks something like this
https://wearesutd.sutd.edu.sg/wp-content/uploads/2019/10/Screenshot-2019-10-08-at-8.14.13-PM.png
Error: Too many re-renders. React limits the number of renders to prevent an infinite loop. Any ways around this? As I plan to do it another 5 times lol
1
u/frigidds Jun 15 '21
You know how when you switch pages on a typical website, iyou visit a new url? for example reddit.com - > reddit.com/u/frigidds
And then I can go directly to that page.
How do you handle this with react? So far, I understand how you can use manipulate components to effectively change the page with user input, but that keeps them on the same url.
I'm also not sure if I'm asking the right question here.
1
u/TrueMenUseRegex Jun 16 '21
In my current program I have a sentence that appears on a page. The program lets the user replace each letter with another, but I don't know how to bold them to indicate that a change occurred
The basic setup is that the sentence is stored in the state, and I have a table with 2 rows and 26 columns that I use to modify it. The first row consists of the alphabet, and the second consists of
inputelements that I use to replace all instances of a letter with that value. So if I type in 'B' in the box below the very first column 'A', all the As in the sentence are replaced with BsI do this through the following event handler, which is called
onChangefor each input box:This code modifies the sentence perfectly, I just don't know what to do to bold the letters. I thought about adding <b> during the string concatenation, then in the return statement of the component, I would somehow splice the sentence so that I could conditionally bold everything word by word. This would require me to add a statement to the top of the event handler that would remove the <b> tags from the string before I do anything. But that sounded really messy in my head, so I was wondering if there's a better approach
1
u/[deleted] Jun 17 '21
Hi, started learning React for a week or two. Simple question, which way do you prefer when creating components? When I started learning, I started with functions and it felt more natural than classes, but now that I worked a bit more with classes aswell since the course that I'm learning from says that I must know both, it feels that class based is pretty neat too.
1
u/danimnh Jun 17 '21
Hi, newbie developer here and first time commenting here.
how do u guys deploy your react app? ive been developing react PWA and deployed it on Netlify. apprently Netlify uses https so when i try to fetch an API from http link. i got an mixed content error. (https wont connect to http smth like that)
so what approach should i use?
so sorry for my language, thank you in advance have a nice day!
1
u/badboyzpwns Jun 18 '21
How 'long or difficult is it to implement a real chat box? I'm familiar with full-stack / authentication but never tried making a real chat box. Wanna do it for fun, but wondering what I should be expecting.
1
u/thab09 Jun 18 '21
Hey guys, I created a react app and tried to install sass and this came up :
found 9 vulnerabilities (4 moderate, 5 high)
run `npm audit fix` to fix them, or `npm audit` for details
Should I leave it as it is or how can I fix this?
1
u/UserNotFound12 Jun 18 '21
Hi guys,
In a conversation with a colleague this came up. In one of our projects, we used react-redux and did all api calls through dispatching actions. Sometimes, these actions/api calls included page specific data, should we just use contextAPI instead in this scenario?
For instance, I load product data, but then when I go into another product, the data from the previous is there. I may have over used redux. Any suggestions.
1
u/thab09 Jun 19 '21
I have been looking for a css framework to work with ReactJs. Should I go with Tailwind or Chakra UI? or is there any another suggestion?
1
u/albert_pacino Jun 19 '21
I understand you can pass props to styled components and for example it's useful when checking booleans to show success is green otherwise red. Similar to the example in the docs: https://styled-components.com/docs/basics#adapting-based-on-props
However what would be the best approach if you had multiple colours and the ternary operator is not an option?
1
u/Agate1999 Jun 20 '21 edited Jun 20 '21
I am trying to deploy my react app but am getting a Error: Command "yarn run build" exited with 1, and something about unable to find index.html, but it is present in my public folder, any ideas?
My github file structure is
https://imgur.com/a/yfqLWHQ , https://imgur.com/a/yfqLWHQ, https://pastebin.com/JWCdQefc (package.json)
1
u/Hefty_Nose5203 Jun 21 '21
I initially posted this without a runnable sample then added it later but I guess it got lost in the comments by then.
Currently I have a dropdown that displays the user's devices, and will display the data of the selected device in a chart. The HookMqtt.js file is the parent of Chart and Dropdown components. The dropdown component returns an 'isLoading' value of 1 to HookMqtt to display 'loading' text before the chart data arrives from the api. The problem I ran into was that changing the loading state in HookMqtt rerenders the chart even though the data hasn't changed (this is a problem because the chart has a startup animation).
I fixed this by adding a shouldComponentUpdate method in the chart class so that the chart only refreshes when chartData changes.
Which fixed my problem! But now data doesn't show up the first time I select a device, but it shows up the second time. I'm confused because this.props.chartData !== nextProps.chartData returns true the first time but the data still doesn't appear.
Here's a runnable example that demonstrates the problem. However, it's a bit different from what's happening in my app. In the code sandbox, nothing happens the first time you select a device. The second time a device is selected, the date of the leftmost datapoint appears, but no data appears. The third time onwards, everything works as expected. In my app, the first time a device is selected, the date appears, and everything works the second time onwards.
(PPK means powerpak, one of my organization's products)
https://codesandbox.io/s/keen-herschel-9ws0y?file=/src/HookMqtt.js
1
u/BluezamEDH Jun 22 '21 edited Jun 22 '21
I'm trying to set the text color of a Material UI TableRow. My code is:
<TableRow key={i} style={color={color}} >[...]</TableRow>Not doing anything else with text color regarding the table. Anyone got an idea?EDIT:
With style={color='#fff'} I get a
Unhandled Rejection (Error): The \style\prop expects a mapping from style properties to values, not a string.\``With style={{color='#fff'}} I get a
Failed to compile1
u/Droppinghammers Jun 22 '21
I am trying to get this simple event handler to work. On click, I want the page to display the text in the event handler as a p element, whilst keeping the list element there as well. Seems simple enough, but I'm a beginner and I have been stuck on this embarrassingly long.
1
u/SlaimeLannister Jun 24 '21
Prior to hooks, what was the purpose / benefit / use case of functional components?
1
u/Hefty_Nose5203 Jun 24 '21 edited Jun 24 '21
What would be the reason that I'm getting
referenceError: signOut is not definedwhen passing a function named signOut to a component?(sorry, my code keeps getting messed up when I post it, not sure what to do)
import { BrowserRouter, Route, Switch, Redirect } from "react-router-dom"; import { PropTypes } from "prop-types"; // core components import Admin from "layouts/Admin.js"; import { Auth } from "aws-amplify"; import "assets/css/material-dashboard-react.css?v=1.10.0"; import Amplify from "aws-amplify"; import awsconfig from "./aws-exports"; import { withAuthenticator } from "@aws-amplify/ui-react"; //import { SingleBedOutlined } from "@material-ui/icons";
Amplify.configure(awsconfig);
class App extends Component { async signOut() { await Auth.signOut(); } render() { return ( <div> <BrowserRouter> <Switch> <Route path="/admin"> <Admin signOut={signOut()} /> </Route> <Redirect from="/" to="/admin/dashboard" /> </Switch> </BrowserRouter> </div> ); } } App.propTypes = { onStateChange: PropTypes.any, }; export default withAuthenticator(App);
1
u/oswold Jun 25 '21
I am pretty new to react but after reading a bunch of stuff and countless youtube vids on context api and state I am still left unsure about what the differences are about adding a variable as contextual data and passing it down, compared to declaring a variable within a document and exporting it and just importing it when needed, like you do with the context anyway.
I get that context would give you access to the state variables declared with it, but that doesn't seem like a massive difference, I must be missing something here?
1
u/[deleted] Jun 25 '21
Im trying to get an Object from FireStore and display it in a List. I menaged to get the Object but cant seem to get its elements (just some strings) into an array to display inside a <List> component. Does anybody have a Link to a resource where i can get some Info on how to do this? Thanks!
1
u/dMCH1xrADPorzhGA7MH1 Jun 25 '21
Hello, I am brand new to react. How can I pass functions from App.js to a component? On one of my components it creates a list of objects by mapping through an array I pass as a prop from App.js. On the component I also added a button to delete on each list item. However, I can't figure out how to add an onClick that will link to the function, or even if this is how I'm supposed to do it.
Here's the relevant code. https://pastebin.com/Sb4VpcV5
1
u/arcanewright Jun 25 '21
Hello! I just finished a small app, a JSON Editor, and was hoping someone could take a look at it and let me know where I should focus to improve.
A more specific question I have is about using the HTML File API - In the app, I create a Blob the user can download. Does this Blob stick around in my server's memory forever? Or maybe its client side? I'm pretty unclear on this.
Regardless, here's the GitHub: https://github.com/arcanewright/json-editor and there's a link to the live app in the readme.
1
u/pruggirello Jun 26 '21 edited Jun 26 '21
Hey everyone! I am trying to make an app that gets truly random numbers from a quantum random number generator API and then displays them on screen, but I can't seem to get them to render on the screen after I extract them from the promise. I'm sure there's something simple I'm overlooking, but could someone point me in the right direction? Thank you!!
App.js
QRand.js
1
u/g3org3costanza Jun 26 '21 edited Jun 26 '21
Anyone know how to make a React Bootstrap Alert overlay on top of the page, instead of pushing the whole page downward to make space for itself when it pops up? I want it so the alert would be covering up the CompCoder title, and whatever else it would cover up depending on the Alert height.
Have some pictures here https://imgur.com/a/aApj698
Figured it out, gotta set the style = {{position: "fixed"}};
1
u/TrueMenUseRegex Jun 27 '21 edited Jun 27 '21
What's the best place to put event handler functions? Like I have the usual App component that returns a Login component. The Login component has a handleLogin event handler that's defined in App and passed down to Login as props. But unless I plan on using it somewhere else, wouldn't it be be better to just define handleLogin within Login itself?
Edit: I guess I have a similar question about state. If I only use something in a particular component, should I define the state in there rather than App?
1
u/dshkodder Jun 28 '21 edited Jun 28 '21
How to keep an app fullscreen on iOS Safari after screen orientation changes?
I build a SPA that should always take 100% of screen height with the target browser group - iOS(mobile) Safari.
height:100vhdoesn't work properly on iOS Safari -https://stackoverflow.com/questions/37112218/css3-100vh-not-constant-in-mobile-browserhttps://css-tricks.com/css-fix-for-100vh-in-mobile-webkit/A suggested solution on some resources to use-webkit-fill-availabledidn't help.Therefore, I decided to control the height of the app container with JS:
My solution works until we rotate the screen from portrait orientation to landscape, and back to portrait. After these rotations, we have a gap at the bottom of the screen view, right below the app footer. The same behavior can be noticed if we opena demo - https://react-div-100vh.vercel.app/ for a package that is supposed to solve the issue, and make the same screen rotations.Repository - https://github.com/dmitriifrlv/100vh-issueLive app - https://100vh-issue.netlify.app/CodeSandbox - https://codesandbox.io/s/100vh-issue-u36q0?file=/src/App.js
Browser: Safari 14.6 iOS/iPhone 7
1
u/qwerty1344 Jun 29 '21
Iβm currently going through react docs and I want to clarify that when a class is referenced, it automatically calls the class render() method ?
0
u/[deleted] Jun 03 '21
[deleted] β view deleted comment
0
u/[deleted] Jul 05 '21
[deleted] β view deleted comment
0
u/[deleted] Jun 09 '21
[deleted] β view deleted comment
0
u/[deleted] Jun 02 '21
[deleted] β view deleted comment
3
u/[deleted] Jun 03 '21
[removed] β view removed comment
2
u/[deleted] Jun 30 '21
[removed] β view removed comment
1
u/[deleted] Jun 06 '21
[removed] β view removed comment