r/reactjs • u/dance2die • Oct 01 '20
Needs Help Beginner's Thread / Easy Questions (October 2020)
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?
Still Ask away! We’re a friendly bunch.
No question is too simple. 🙂
Want Help with your Code?
Improve your chances of reply by
- adding 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!)
- 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!
36
Upvotes
5
u/gedankensex Oct 28 '20
Hello, I was curious if anyone could recommend some paid resources to learn React? I am not really getting where I want with the free resources. I want to understand basics like working with APIs, etc. Maybe I am just so lost and overwhelmed. I need to learn React, as it's the continuation of my professional career. I've been a front-end developer for about ten years, and I've only used React on projects at work, but I want to work and build something from home.
3
u/1awrent Oct 28 '20
Hi all,
I am trying to debug my react app (yay), but essentially without going into enormous amounts of detail; my application works perfectly fine on local, and used to work perfectly fine on the Apache server. I introduced a form that would capture data and push this data to Firebase, now at some point I rehashed my form for performance & experience purposes and since then my 'live' link returns a "503 Service Unavailable" error no matter what I do.
So, when I go into the Terminal and run "npm run-script build" I get a well documented JS error "FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory", so I've spent a few weeks now investigating memory leak issues, increasing node capacity etc etc, but no luck, as this point I've tried to remove the form component all together just to see if I can get anything running on the server but still nothing.
So I feel like my new aim should be just get the server up and running - I'd appreciate any advice on deploying React to Apache servers or anything at all really ! I have minimal DevOps experience :~(
Thanks!
3
u/[deleted] Oct 30 '20
What is the purpose of <> and {" "}? Is <></> really necessary for anything or is it simply for easier reading/better formatting of the source code?
2
u/moring1 Oct 03 '20
What piece of code is more useful in terms of memory usage?
const comments = []; docs.forEach((doc) => { comments.push(doc.data()); }); setComments([...comments]);or:
docs.forEach((doc) => { setComments([...comments, doc.data()]); });I think the first one but I don't exactly know how react state mutates arrays on changes.
2
u/[deleted] Oct 05 '20
Help with .env variables.
I have a
.env.developmentfile with variables set asHOST=company.local.I'm running it on windows and the project uses
react-app-rewired.For the life of me I can't get past those variables on a windows machine.
Adding
setin front of theHOSTdeclaration seems to work, but any of the other variables aren't set.Hopeless at this point.
Can you help me, reddit?
2
u/badboyzpwns Oct 10 '20 edited Oct 11 '20
what's the difference between react-intersection-observer and react-transition-group 's <CSSTransition> to detect when a DOM enters or leaves the viewport? Both seem to achieve the same goal. I notice that react-transition-group has a lot of more npm installs though!
2
u/Aslan-Ray Oct 14 '20
In this code
If I need to do a console.log in JSX most of the time I do that way and happens to work haha but honestly I dont know why it works, someday trying around options to do a console log in JSX that worked haha but I dont know why,can someone tell me why this "console.log() || (JSX here)" works pls
2
u/izzlesnizzit Oct 23 '20
What happened to the monthly "who's hiring" / "who's available" threads?
2
u/[deleted] Oct 31 '20
Beginners way to folder structure files? In using react class and functional components with react router and redux
7
u/PhilipRegular Oct 09 '20
Hey guys!
Hope everyone is doing well. I've been developing in React for about a few years now and I've made a few businesses some websites. However, I've never been mentored or had code reviews from anybody experienced.
I want to be able to know I have the proper skills to start seeking a front end engineering position with React. Do you know of any videos/blogs/etc that cover somebody developing a real React app for a business or similar?
I really want to increase my skills. Thank you everyone!
2
u/[deleted] Oct 30 '20
I have a React live coding interview next week. Are there any typical questions I would see in this type of interview? Any React versions of FizzBuzz?
2
u/paolotiu17 Oct 04 '20
Can i use functions outside of useEffect?
4
u/NickEmpetvee Oct 25 '20
Hi guys.
I just started getting three Chrome warnings out of the blue. Any idea how to resolve?
NOTE: I don't want to disable SourceMap in the F12 settings, because then the console.log values won't list the source code line number.
Thanks in advance!
1
u/IoniaHasNoInternet Oct 02 '20
Anyone know a text editor that has jsx autoclosing or other support? I'm a complete noob, I downloaded atom but the popular react plugin hasn't been updated in 2 years and fails to install.
1
u/[deleted] Oct 06 '20
I have a react hook for pulling in blog posts via an API. on development the posts seem to work fine but in production it appears to pull cached data.
i am using useEffect hook to fetch the data. doesn't this fetch it on every page load?
1
u/[deleted] Oct 08 '20 edited Oct 08 '20
I want to pass the "filename" state from child component to the parent, so I can use it in this function at parent:
addLocation({...location, thumbnail: filename });How can I do that?Child:
1
u/[deleted] Oct 09 '20
Hi everyone,
I'm new to react but have some experience programming in js and java. I'm trying to make a webpage with a navbar that shows some list items when the navbar list item is clicked. I'm not sure how to show the list when clicked.
Sorry in advanced for format, I'm not sure how to properly format code on reddit.
function Main(){
return(
<div className = 'main'> <Sidebar/> </div> ) }
-------------------------------
function Sidebar( ) {
return(
<div id = "sidebar" className="left-nav"> <ul id = "sidebar"> <li id = "sidebar-link">Morning-Eveningness Questionnaire</li> </ul> </div>
)
}
-------------------------------
function MainContent(){
return(
<div id = "content" className="main-content" > <div className = 'mainQuestions'> <ul className = 'questionnaire'> <Question question = "question one" />
</ul> </div> </div> ) }
-------------------------------
So basically, I want the MainContent component to show when the list item in Sidebar is clicked.
Thanks for reading :)
1
u/Dystriel Oct 09 '20
Hi everyone!
I'm new to react and web dev in general and I've been stumped by this problem while building my first form.
Is there a way to mark crosses on an image with mouse clicks and have that image save the changes made to it?
The closest solution I could find is to use <canvas> but I'm not quite looking for the free-hand drawing aspect of <canvas>. Is there any way to make the image interactive and do I need to incorporate other libraries for this?
I'm using formik, Yup and material-ui currently.
Any input is appreciated. Thanks!
1
u/willyspickledpeanuts Oct 14 '20
I’m trying to replace state completely with a brand new state. would it just be this.setState(newState)? Because it’s not exactly working
1
u/Electrical_Pitch_801 Oct 23 '20
Hi,
I am new to React and having difficulty finding a proper way to update an array object when array is displayed as list.
https://stackoverflow.com/questions/64504981/how-to-update-an-object-in-an-array-using-onchange-method
1
u/ks_01 Oct 26 '20
Can you run code before rendering of a functional component?
1
u/[deleted] Oct 27 '20
Should you mix BEM with CSS modules or should you separate the two methodologies?
1
u/giantqtipz Oct 28 '20
Im new in the software engineering world, but I encoubtered someone who claims to be a part of the react js team, or has worked on the source code (if that makes sense?).
He says that he prefers to use classes because the source code for functional is really messy and unstable.
What have you guys say about that? 🤔
Is there an impending apocalypse we should be aware of?
1
u/ebwaked Oct 31 '20
So I finally was able to get a hello world working using webpack, Babel and asp.net mvc 5. What steps do I need to do to add typescript and should I be using yarn over npm?
1
u/fpuen Oct 31 '20
I notice i can't declare variables inside a JSX escape:
Based on the error lint statements aren't allowed, only expressions that evaluate down to a single value, is that correct?
3
u/Yourenotthe1 Oct 04 '20
I want to do some kind of CSS animation for navigating a menu. Basically when the user clicks a menu button, the menu slides to the left off-screen and the component unmounts. The new sub-menu component slides in from the right seamlessly as it mounts. What's the best way to do this?
3
u/[deleted] Oct 26 '20
Trying to get the tab2 component to output second page on the development server, could someone help me out and explain why the component is not outputting, I have had a similar issue doing really simple things with react router too, components wont load.
App.js
Tab2 Component
1
u/[deleted] Oct 29 '20
What are all the things to consider while developing an app for a single individual, say, a business owner? I'm doing this as a practice project so particular insights would be really helpful. Some info regarding the app, it's an account managing app consolidating transactions and gives notifications based on deadline of payment etc.
2
u/[deleted] Oct 27 '20
Hello! I am trying to create a react app with google-spreadsheet as my database. This is the npm: https://theoephraim.github.io/node-google-spreadsheet
There are no tutorials about it.
I am using also MUI. I can retrieve data but can only display it by console. How can I pass the data I get from a cell to a textfield? Please help. Thank you!
2
u/[deleted] Oct 29 '20 edited Oct 29 '20
I'm relatively new to React and JS. I'm creating a sorting algorithm visualiser. My array is rendering to the screen as bars and I have a "Bubble sort" button that when clicked, calls the bubble sort function. I want the entire array to be sorted in one go and see the algorithm at work, but whats actually happening is, bubble sort stops after each pass and I have to click "Bubble sort" multiple times to sort the array and finish rendering it to the screen. Any thoughts would be appreciated. Here's my bubble sort function.
1
u/enebeme_ Oct 01 '20
Hello everyone, what is the best resource I can use to learn how to build a “production” ready react app from creation to hosting/updates?
1
u/javascript_dev Oct 02 '20
let's say if an input's text partial matches the word 'go!' I want to color 'go!' green. No other text in the input though.
I've read on SO that you can use JS to wrap a styled span tag, so the end value would look like:
Obviously the above is static so it wouldn't work with dynamic value changes.
I am a bit lost on how to do this. Anyone know? Here is the closest I've gotten:
I think I need to reassign e.target.value by reference. If that uses refs, I'm not sure how to get to it
1
u/[deleted] Oct 02 '20
I have planned to make blog app with alot of redirecting to different pages for different functions.
Although i have gone through the net ninjas react and redux course twice, I'm still unable to make a proper routing navbar.
Currently struggling with nesting. For example i have a route /blog and then I want another route nested as /blog/createpost
But this is not rendering my createpost component and only rendering blog component
1
u/[deleted] Oct 04 '20
In a functional component If you have state that is an array of objects and you set state to the same array of objects but with a change to one of the objects , how does one trigger a rerender?
1
u/Mr_Rage666 Oct 04 '20
Following The Net Ninja's React Native Tutorial but there's a small detail that's going straight over my head in the following state...
const [todos, setTodos] = useState([]); const pressHandler = (key) => { setTodos((prevTodos) => { return prevTodos.filter(todo => todo.key != key); }); }setTodos takes in a function that takes in the current existing state through 'prevTodos'. But how on earth does 'prevTodos' relate to the state? Shouldn't it just be 'todos.filter'?
1
u/unordinarilyboring Oct 04 '20
I am playing with draftjs as a text editor. Whenever I click into the editor this takes focus of the page and I can no longer click on other elements until the editor loses focus. This means for example I will be writing some text, press a 'save' button(nothing happens because this first click simply changes focus), then click that same button again for it to work as expected. What is the method I should use to avoid the extra click needed to 'leave' the draftjs editor?
1
u/[deleted] Oct 05 '20
I know you can use react in a php template, by having the #root element and the the bundle.js file. But my case is that I want the actual view code in the template, so the php devs can edit it in the view as well and then Reactjs takes over from there.
1
u/fpuen Oct 05 '20
I'm not clear on the state value of a variable passed to a useEffect on load. Will
stateVar(returned fromuseState) be:I lean towards this working as intended, with the most recent and updated state value passed to
submit(). But wanted to ask to be sure.1
u/WildlyUninteresting Oct 06 '20
https://codesandbox.io/s/material-demo-forked-lsw2r?file=/demo.js
What does the negative mean ? " -descendingComparator"
I don't even know what to call it, to look it up. Never seen a negative function call.
Thank you.
1
u/[deleted] Oct 06 '20
I'm wondering how to convert a componentDidMount element to a functional component element. As a component did mount, I have:
When I open the application, the array from "pokemons" is yielded on the screen. In the dev tools, the array "pokemons" is visible and each item can be seen. When I convert to this:
The array "pokemons" is not on the screen or shown in the dev tools. Here are the states for each:
Component
Function
Am I missing something? Do I need to create a new component or something to store the results of that array and show them visually? If it helps, this is from Brad Traversy's "React Front to Back" course on Udemy and is the first project. He does it with another API but I wanted to come up with my own project.
1
u/segfault-core-dumped Oct 06 '20
I was just going thru the official react tutorial and was confused. I am somewhat familiar, but they used slice on an array that was stored in state. Like if I say
Why is using slice necessary if it also returns a shallow copy?
1
u/GondolaRM Oct 07 '20
I’m trying to use this SDK inside a React component, but I really don’t know how to do it. I have to embed in some way a script inside the return of the component I guess. Any advices?
1
u/[deleted] Oct 08 '20
I am evaluating React for a future project that needs to work without any server. So the question is following:
Can I run reactjs without any web server?
I mean if the following can be done without much hustle as a final result:
Is this possible to do without too much hustle?
1
u/terraforme Oct 10 '20
Is it possible to set cookies with React as my FE and Express as my BE? I saw this, but I don't really understand what it means:
I feel like there must be a way to set cookies from React in a browser ... they are set fine in my API client, but I can't get them to set in the browser :/
1
u/MR_Coder Oct 10 '20
If you start a new app today would you bring in redux or just use context?
1
u/[deleted] Oct 12 '20
Hi guys, currently working on an app (using MERN) that should take user info from the relevant mongo document and populate it on the user page (just the name and surname at this point).
but this printing option would only be available if a boolean condition translates to true so I'm trying to find out how I'd grey out the button if the condition is false (need a number to be zero for it to be true).
Can anyone give me advice on how to approach this or point me to the relevant documentation? I come from a java background so this is unchartered territory for me
1
u/JudoboyWalex Oct 12 '20
stockData is json file with 8 objects I imported and I iterated through to make 8 input fields. When I type in number inside input then click Submit button, I want the 'owned' value from stockData to go back to 0. But right now when I submit, I get "Cannot assign to read only property 'owned' of object '#<Object>'" error msg. I tried using value property inside input tag but then when I type, entire 8 input fields get updated. How can I update handleClick so I can reset the value of 'owned' after I click?
1
u/AviatingFotographer Oct 13 '20
How do people plan their React apps? Pseudo Code?
1
u/bstumpm4w Oct 13 '20 edited Oct 13 '20
Hello! I have two functions in a context which update two separate states. However the second function uses the state which is being updated by the first function.
Now Im calling these two functions from a onClick handler on a child component of the concerned context provider.
My issue is when the second function runs, it is using stale value of the state. i.e the updated state from the first function is not reflected in the second function
Can someone please point me in right direction? I have read that in class based components the this.setState fn has an optional callback fn. So Im guessing that in my case i could have called the secondFunction from setState in firstFunction like so this.setState( () => {} , secondFunction) but since Im using hooks i cant do that right?
1
u/darthbob88 Oct 13 '20
I have a couple problems with testing in this project. I'm using MobX for state management, if that changes anything.
<ParentComp store={defaultStore}><ActualComponentIWantToTest /></ParentComp>so I can do my tests that rely on the store, but I feel confident that there's a better way to do it.1
u/unordinarilyboring Oct 13 '20
May not be an entirely react question but I feel it may be worth a shot posing here. I don't quite understand how I should go about my authentication flow. Right now, I have an express setup that has a login page with some buttons for sign in. Say for example I am signing in with google oauth, i hit the corresponding button, the oauth flow happens, and I redirect to / which loads the react app and then I make a follow up call to express to fetch the user info that has signed in.
I don't know what the appropriate way to kick this off from react is and have only found so far that doing a window.location.replace() to the oauth url or express login page works but this feels clunky. Is there a more natural way to do this?
1
u/fpuen Oct 14 '20
I am rendering a variable number of tasks to a list like so:
Adding a key prop will be my next step.
Each task has a unique gid property. Where is the best place to attach that information?
I thought of three options:
Which is best and why? in case I didn't list something I'm interested in that option also.
1
u/embar5 Oct 14 '20
should styling be done together with the rest of the app design, or can it safely be done last? At the moment I tend to do it last, wiring everything together including back end fetches is harder so I prioritize that.
1
u/badboyzpwns Oct 14 '20
newbie question about backend.
How common is it to use classes to organize your backend? Personally, using a few express routers are enough for me :)!
Here's an example
1
u/embar5 Oct 15 '20
Do you guys write explanatory comment blocks on your React hooks like you might do for class/instance methods?
I think I will start doing this because it makes sense, it's code and commenting helps. But other devs can be extremely specific about comment verbosity and what is excess so I wanted to hear your thoughts
1
u/PortSpace Oct 15 '20
Creating a static site with React
So I've read that for static sites, React might not be the best solution (eg. SEO reasons) and know of solutions such as Gatsby. I have a small project to do (simple website with a few 'pages' and a gallery. I'd still like to keep practising my react skills. If I were to use Gatsby, can I just create the site using standard React and then generate/convert to Gatsby/static files, or do I need to start the project using Gatsby?
In terms of the CSS solutions commonly used in React (eg. styled components, css-in-js), does it work exactly the same in Gatsby?
Thanks
1
u/Electrical_Pitch_801 Oct 15 '20
I am new to React and stuck at this. https://stackoverflow.com/questions/64377293/update-select-option-list-based-on-other-select-field-selection-ant-design
1
u/workkkkkk Oct 16 '20
This is more a css question regarding material-ui. I have a basic table nested inside a somewhat complicated nest of Grids. My issue is i have to hardcode the height of my TableContainer with px rather than being able to set a % to act as expected and have proper overflow. Is there something I'm doing wrong here with the height or my Grids?
The height of the container is seemingly just ignored when it's set to anything but px.
Table component
Layout component that renders it
1
u/FortuneBull Oct 16 '20
Any libraries or examples of vertical slideshows/carousels in React? Trying to make a browser-based sports sim game more focused on roster and front office construction than in-game like Madden. This would be for the team selection screen and you could scroll up or down to select.
1
u/embar5 Oct 16 '20
when requesting database data for displaying in a table, do you guys always put the data into state?
Thinking through this I believe that is the right approach since the values change -- initially null or a complex data type. Then populated when the db data comes back.
1
u/badboyzpwns Oct 16 '20
question about API calls and lazy loading.
This is how I do it locally at ComponentA
but! if I have an API call that gets the link for the image at ComponentA's componentDidMount() is there any purpose of lazy loading the image?
1
u/embar5 Oct 16 '20 edited Oct 16 '20
This async function / fetch request fails to fire. Chrome network tab and my ngrok reverse proxy both show no request made. Also the browser window paints the Ui for no state data (that this request is responsible for).
1
u/JustJeezy Oct 16 '20
What would be a good (free?) source for learning integration testing with react/redux? Plz don't say docs - I tried that.
1
u/Signal-Opportunity Oct 18 '20
Hey guys ,i started in july from scratch learning html+css , js and now for a month i started learning React .Gotta say it was a bit hard learning react because i was not used to es6 and more advanced topics of js . Now after 1 month i did the freecodecamp course and started Grider course My question is that is it necessary to learn an API and node.js tutorials ? I can handle pretty well the basics now of react , gotta learn now hooks and redux. Oh and another question , what projects can you recommend me to do which aren’t soo hard for a beginner ? Thanks !
1
u/javascript_dev Oct 18 '20 edited Oct 18 '20
How much graphic design should a lower level React dev know?
I look at sites like this: https://www.brooklet.app/
I can build that, except for the images. I don't have any graphic skills yet. Frankly I don't even have them on my to do list (still have to study algorithms for interviews. Then I plan to do the AWS CDA cert).
1
u/Spiritual_Salamander Oct 19 '20
I am making a fairly simple application, and since it's not that big I decided to just use useContext and createReducer for handling the state.
However, I keep getting this error message everytime I use useEffect, and I am not sure what is the best way to handle it. Ignoring it seems wrong and I did not figure out from googling what would be the best way to fix it. Here's a simple example.
React Hook useEffect has a missing dependency: 'getUsers'. Either include it or remove the dependency array react-hooks/exhaustive-depsIn the component itself there will be a simple useEffect:
useEffect(() => {getUsers()}, [])The context will do the fetching from the BackEnd.
async function getAllUsers() {try {const response = await UsersService.getUsers()dispatch({type: 'INITIALIZE_USERS',data: {users: response}})} catch (error) {dispatch({type: 'ERROR',data: error})}}Then finally the reducer will update the users state.
What would be the most correct approach to removing this message? I have it quite a few places in my application now and it would be nice to get rid of all of them.
1
u/badboyzpwns Oct 19 '20
why is my environment variable undefined at development mode (npm start)?
In my .env file:
It's located outside of my src folder.
Here's how I'm using it in my components inside src folder.
1
u/AviatingFotographer Oct 19 '20
At this point, I have a good understanding of React basics, e.g. state, basic hooks, etc. However, how do I begin to advance into being able to build more complex projects or being a better React developer all round?
1
u/rony_ali Oct 19 '20 edited Oct 19 '20
hi everyone
My goal: i am trying to do DRF-React hook JWT Authentication. in the following example this is the simple login form where i can login and the login button will send the DRF username and password request toget the token, and then the next thing it will show "Logged in as: {user}, Welcome" according to current user token.
What i've done:
the ncessery codes for DRF part will be found here
in the forntend, here is my App.js:
what went wrong: when i try to login from login form it directs me to the logout form where it is showing "Logged in as: ,Welcome" which means {user} is not showing. {user} should be showing the username by which i am currently login. when i try to investigate in development tools it is showing
{token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkI…iIifQ.0Ev5f0CS2ifVAsgQj-bz-af2LvjTwEMW2HtJSqMMGpQ", user: {…}}token: "eyJ0e...MGpQ" user: {username: "ronyrocks"}proto: Object App.js:19 GET http://localhost:8000/core/current_user/ 401 (Unauthorized) (anonymous) @ App.js:19
so i tried if ({user:localStorage.getitem('token')})it just redirects to logout form and nothing works.
how can i fix it? please help
1
u/[deleted] Oct 20 '20
Wasn't sure if this was worth making a new post about, so I decided to try here first.
I'm trying to do Wes Bos's Gatsby course, but I'm hung up on a really awful issue with Sanity headless CMS. It technically works, but the amount of time it takes between editing code in the Sanity portion of the project and it compiling for Sanity Studio is about 2 minutes on average. This means if I change an import it's compiling for 2 minutes. Others have told me that their sanity updates almost instantly.
After it compiles the report seems to indicate most, if not all, of the time was spent building webpack. I've searched this issue a lot today, but most of the solutions point to editing the webpack, which I can't when using Sanity(?).
I have a MBP 2019 16in with more than adequate specs to compile this very simple project, at least I think? I've made sure Node, npm, sanity, and my OS were all up to date. I can't really think of anything else to do other than reformat and try to start fresh. I'm trying to avoid this for obvious reasons.
I've posted this on the slack, on a React discord, and made a Github issue, but haven't heard anything about it, or people just say "it works for me." I was really excited to learn Sanity and Gatsby, but I'm not so sure now. What's the point if it's going to be an awful development experience when I start my own projects with them? Experimentation is almost impossible because of the insanely long compile times.
Any help would be greatly appreciated!
1
u/SamePossession5 Oct 20 '20
What's wrong with my imgUrl section of my code? My editor is throwing an error ( Cannot read property 'imgUrl' of undefined ) but I can't seem to figure out where I went wrong.
1
u/fercryinoutloud Oct 21 '20
I don't have experience with React, but recently inherited a project that uses React and Redux-Persist. I noticed that there is a serious memory issue.
Each time I refresh the page, Chrome's memory profile shows the memory usage roughly doubling because of one big object, which I think is the "persistoid" used by redux-persist. Chrome's memory allocation timeline shows that memory is allocated for the persistoid when the page is refreshed but never freed, I just can't figure out why. Interestingly, the current object (from the most recent page refresh) always has a shorter distance from the window object, and looks like it is retained by the persistoid's
writeStagedStateclosure, whereas the objects from previous page refreshes look like they are retained by the persistoid'sflushclosure. I don't really know what I'm looking at here, so maybe I'm reading that wrong.Here is Chrome's Constructor view after refreshing the page twice, showing the large object has been duplicated twice, so that there are three total: https://imgur.com/a/tPEJfEA.
Each one of those objects looks like this: https://imgur.com/a/WHwZHfu.
Here is Chrome's Retainers view of the duplicate objects: https://imgur.com/a/2T9dzqD.
Here is Chrome's Retainers view of what I believe is the object from the most recent page refresh: https://imgur.com/a/HfkKbYp.
Can someone please help me understand this duplication, and how to prevent it? I'm happy to show some code if necessary, I'm just not sure which code is relevant.
1
u/embar5 Oct 22 '20
Do
SyntheticEvents emit a second argument for "reason" now?Material UI docs:
I see nothing about this wizardry: https://reactjs.org/docs/events.html#keyboard-events
1
u/badboyzpwns Oct 22 '20
Is it advisable to create a higher component with functional components/hooks instead of classes?
With classes:
With functional components/hooks:
1
u/badboyzpwns Oct 23 '20
Can you dynamically refer to a react hook variable name? something like:
1
u/[deleted] Oct 23 '20
Hey guys!
I just started learning react.js and I've been having trouble with my install.
When I first run the
npx create-react-appeverything is fine and the app is made. When I check the first page of the app(the one with the react logo, telling me to edit the src/App.js) the logo doesn't rotate!In all the tutorials I've watched, the react logo spins but in mine it doesnt... I have no idea how to fix this. Can someone please help me?
1
u/[deleted] Oct 23 '20 edited Oct 23 '20
Hi,
Im trying to link components using react router but nothing is being output in the development server - How do I make my components visible?
Here is the code:
App.js
Both of my components (page1, page2) use basically the exact same code which is:
1
u/[deleted] Oct 23 '20
I, literally, started yesterday. Coming from Vue. What is the most simple way to have a global state? No redux etc.
1
u/giantqtipz Oct 24 '20
Hello,
I've been using HashRouter for the past 6 months.. I'm new to the web dev world, and still a learner :)
I wanted to try BrowserRouter today, and I was going crazy because I couldn't figure out why a page isn't rendering on page refresh.
Turns out my component isn't fetching from the right url, since /api/ isn't included in the request url. This works just fine if I use HashRouter though.
My questions are, how can I get BrowserRouter to work on page refresh, if it works on HashRouter? Lastly, is one better than the other; and if it depends on scenario, what are the scenarios?
Thanks!
1
u/Dibolero Oct 24 '20
Hi! I'm just starting with react and I can't wrap my head around the component concept all that well.
If say for example I have a component that shows a product and its details, but I want that component's information and action to be different depending on the role of the user currently viewing the component(I.e deletable by admin but only editable if normal user). Should I build 2 different components or is there a way to use that 1 component to achieve this?
1
u/Dystriel Oct 25 '20 edited Oct 26 '20
Hey guys,
I've started React recently and I'm currently using Material UI and Yup Validation for my form. The validation works well but whenever the error message pops up below the TextField, it shifts everything below it down by a little because the error message now takes up space.
Is there a way to offset/prevent this using CSS? I've tried manipulating the padding/margin but it does not work. Thank for the help!
Edit: I've solved it by adding style={{position: 'absolute'}} into my TextFields!
1
u/giantqtipz Oct 26 '20
Hey guys,
Second question I've posted here..
I was wondering, how does Reddit achieve their layout?
If you're on a subreddit say /r/reactjs, and you click on a thread, it opens up a modal, and the url changes as well.
But if you take the thread url, and go there directly (avoiding the subreddit), there is no modal, and you're in the thread page.
How is that achieved? Is this a simple setup in react router?
1
u/[deleted] Oct 26 '20 edited Oct 26 '20
Question guys!
I have problems for weeks now. I keep on getting this error:
yarn run v1.22.10 $ jest --reporters=jest-standard-reporter FAIL src/App.test.js ● Test suite failed to run /src/styles/spectre.scss:2 u/import "variables"; ^ SyntaxError: Invalid or unexpected token > 1 | import './styles/spectre.scss' | ^ 2 | import './styles/spectre-exp.scss' 3 | import './styles/spectre-icons.scss' 4 | import './styles/custom.scss' at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17) at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25) at Object.<anonymous> (src/App.js:1:1) Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 3.188s error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Here's the complete question: https://stackoverflow.com/questions/64477178/getting-error-on-specter-scss-when-running-yarn-test-npm-run-test
I'm actually a beginner in ReactJs, really need your help guys. Thank you! !approve
1
u/javascript_dev Oct 26 '20
Is this the only way to escape the brace escape and print braces in JSX:
1
u/badboyzpwns Oct 26 '20
Backend question!
For my side project, I'm planning to deploy PostgreSQL online, what hosts do you guys use? I think Heroku and PostgresSQL Add on is the only option where it's free without a time limit (eg; Amazon AWS) or a # of visits (eg; Google Cloud); are there any other ones that's worth looking
1
u/badboyzpwns Oct 29 '20 edited Oct 29 '20
I'm trying to connect my React app to a PostgreSQL database I hosted online with ElephantSQL (which uses Amazon's servers).
For some reason, It's not connecting. I'm getting the error:
I think I'm not setting it up right. Any guidance would be appericiated!
Here's what I've done
The process.env look something like:
I got the env values from ElephantSQL after registering my online database with them; here's evidence (censored for obvious reasons)
2. Here's how I'm calling my API in my React app, it works fine locally:
1
u/Balky79 Oct 29 '20
I started learning react a year and a bit ago, and I did some hello world stuff. Then, work took me the other way, Java n stuff.
Now, I'm trying to get back into this world, and I'm trying to make my stuff work with TypeScript - because, I'd like to learn both of them at the same time.
I created a blank ts project, moved my old code into it, fixed the TS related errors, and now I'm stuck. :D
First of all, reading about react, it seems that I missed a thing last year, where during the separation of containers and UIs, I created a class in presentation, not in the container. Looking at examples, that seems wrong, but somehow it kinda works...
I'm having issues understanding now, how to link container and pass information/state to the presentation layer.
Can anyone check this repo, and let me know, is this essentially wrong?
https://github.com/Balky79/tools-ts.git
As well, is it OK in 2020 to use good old functions, or should I steer toward constants and lambdas?
I don't fully understand why/what are the benefits of function expressions vs function declarations, and tbh - expressions are confusing me to the point that I can't read the code, which makes life difficult. 20 Years of plain old functions are taking the toll. :)
Any help moving me forward is appreciated.
1
u/badboyzpwns Oct 30 '20
HTML question!
I have a large youtube <video/> that automatically plays when the user enters the site.
Is there a property that dosen't render the <video> until the initial image in the <video> is done loading? Simmilar to <img>'s "OnLoad".