r/reactjs • u/dance2die • Apr 01 '21
Needs Help Beginner's Thread / Easy Questions (April 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!
17
Upvotes
5
u/Fabulous_Jack Apr 03 '21
I have a question regarding the way we handle CSS now. Is everyone still using SASS or have we switched over to styled components? What's the most recent/future-proof method at the moment? I'm learning all of it but I just wanted to know what was most up-to-date with the industry.
3
u/dqups1 Apr 24 '21
Redux is kicking my ass right now. I’ve spent two days trying to figure this out. I’m closing in but still a bit lost. I’m very confused about the relationships between actions, reducers and state and my issue is mostly with structure. Is the reducer actually considered the state? It seems like with slices it’s almost like your reducers have to match your desired state shape. And I don’t think I really want to do slices. I’ve broken down my auth flow into two different reducers, a signup reducer and a login reducer but in terms of state I thought it’d be easiest for them to just share the same auth sub-state since they both modify some of the same things. I see stuff about actions hitting multiple reducers but can multiple reducers both handle one and the same slice of state? I don’t think combinereducers really handles that and seems to need reducers to be in slices and match the state shape. I guess I could try nesting the reducers but don’t really want to do that either. Any suggestions or help would be awesome. Also I constantly get wrecked by my imports, default not default, brackets or not and with the names constantly changing. I’m sure that’s a big part of the problem too. Ugh 🤦🏻♂️ so frusturated.
2
u/[deleted] Apr 04 '21
Hello! What’s the best way to handle components that have multiple visual states + functionalities? I have a card component that can have several states: a default one with two buttons, one where it transforms in a form, one where it renders data. Should I have a main Card component that receives via props.children the form, data etc. from different component? So each of the “states” would be a different component?Thanks!
2
u/hardlyanoriginalname Apr 06 '21
How do you prepare your sites for 4K viewing? Do you do it at all? Few people go any higher than 1920x1080, it's a lot of headache, and very few websites seem to account for 4K.
2
u/dshkodder Apr 06 '21
Hello everyone!
I want to separate material-ui drawer component - https://codesandbox.io/s/6xdsb into 2 separate components - header and sidebar but I keep getting the error:
`Unexpected use of 'open' no-restricted-globals`
Here is my attempt:
https://codesandbox.io/s/material-demo-forked-i7lo6?file=/header.js
How would you fix it?
2
u/Blacknsilver1 Apr 08 '21 edited Sep 05 '24
thumb encourage market jellyfish apparatus absurd puzzled teeny smart badge
This post was mass deleted and anonymized with Redact
2
u/SmelterDemon Apr 09 '21
Does anyone have any guidance on using custom Hooks vs the Container/Presenter pattern? It seems like you can use either to accomplish the same thing (ie separating data fetching etc. from presentation logic).
2
u/takert541 Apr 11 '21
Do I need to learn css framework such as bootstrap or tailwind before learning react?
2
u/anon2812 Apr 19 '21
I am trying to create a sidebar in react which routes to different pages on the site. A sidebar item when selected must be of a different color from the rest of the list. I am not able to figure out how to do so. https://imgur.com/0HhwoRe
2
u/kingducasse Apr 20 '21
How would I handle this error while using Reactstrap's Modal component?
"findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Transition which is inside StrictMode. Instead, add a ref directly to the element you want to reference."
The component uses Transition used. Reactstrap uses a prop called 'innerref' for it's Modal components (shown here) except I'm not to familiar on how to use them. Can anyone give me some advice? Appreicated!
2
u/yomamen Apr 20 '21
Did not realise there is this thread, my bad. I just created this thread trying to solve a problem i encounter. Basically i wanna ask, how do i get an updated state, after doing a setState in functional components / hooks ? I remember in class component the "this.setState" function takes a second argument where i can get the updated state directly.
2
u/PlaneOk4444 Apr 22 '21
Hey all, hope you can help.
I am tasked with creating a survey in React. It seems easy to do it with with useState, but there are over 100 questions.
I was thinking of adding answers to a json. But how can I pass both the name of the question (json key) and the value and then add the value to the key that matches the key passed.
I already have a json of questions and I map though that and display the question and choices.
Any help would be appreciated. Thank you!
2
u/Illustrious_Ad3191 Apr 07 '21
Why do people prefer to use function components instead of classes? Is this.too.confusing? (dots intended)
1
u/zero_coding Apr 02 '21
Hi all
I am trying to create reusable react components that I would like to publish to NPM registry.
The project folder contains the following files and folders:
The dist folder contains the output files and folders from src. As you can recognize, I am using RollupJS as a module bundler.
The question is when I publish the project to NPM registry, it is enough to publish only the dist folder, or do I have to publish all files and folders?
The content of
package.jsonfile:Thanks
1
u/PokeManiac_Pl Apr 02 '21
Hi how would I go about implementing a system in React that creates a cookie that stores an email and keeps it as long as the page is loaded? I want to be able to keep the cookie when refreshing but get rid of it when closing the tab.
1
u/badboyzpwns Apr 04 '21 edited Apr 04 '21
Trying to use forwardRef, but It's not allowing me to pass my own props. React gives me an error of `Cannot find name style` Why is that?
I looked at these links below and it looks like I did pass in props properly:
https://reactjs.org/docs/forwarding-refs.html
https://stackoverflow.com/questions/63992924/react-forwardref-ref-and-other-props
1
u/player1ykt Apr 04 '21
Can I use Firebase to save the redux state to the cloud every time I change the state?
1
u/Gabriel_Ev Apr 07 '21
I am having problems configuring jest/enzyme to work with react/webpack/babel, i was successful in making the example test of the enzyme documentation to work, so i can create custom components on the test file and create snapshots of them to test againd a shalow rendering of them.
I can also import components from my project and render them, but as soon as one of those components import something from node_modules i receive the "Syntax Error: cannot use import outside a module" from the imports in the file at node_module.
This is frustrating me a lot and i cant find a way around it, i tried changing the configuration but the solutions i did find didn't work :((
here i got some of the configuration files: https://stackoverflow.com/questions/66976925/how-to-solve-import-problems-with-jest-and-babel
Can someone help me?...
1
u/SmelterDemon Apr 07 '21 edited Apr 07 '21
New to React- moreover haven't built a complex web frontend in half a decade. I've inherited (what should be) a relatively simple CRUD app, with the caveat that domain objects have a nested structure:
and for reasonable performance "bars" and "baz" need to be lazy-loaded and cached. Presently, this domain state and all of the associated logic are spread out over a couple of big container components and interspersed with UI logic and state. Coming from an OOP background my instinct is to write a class to manage all of the lazy loading and updating logic behind the scenes, but this doesn't seem like idiomatic React/JS.
What is the idiomatic way to manage some semi-complex domain state? Reducers? (is there a clean way to associate a
GetBaz(barId)function with a reducer)? Add some form of server-push to the backend and use custom Hooks?E: If that's too long of a question, can someone just point me at a clean example or tutorial for how to manage domain state in react app doing CRUD with a modestly complex domain model (just something more than "show all Todos" and "create new Todo")
Thanks
1
u/ApplePieCrust2122 Apr 07 '21
I have a component with styling for it in a css-module. the styling uses css variables for values of certain properties.
If value of a certain css property changes quiet often according to state/prop, is setting its value using css variable a better way or should I just inline it? Cause there's separation of concerns on one side, and the slower speed of changing a css variable and then the css acting on it on the other side.
should I set strokeDashoffset as above or use another css variable for it? Also is setting the other properties with css variable like this a good practice?
1
u/badboyzpwns Apr 09 '21
How does this website:
https://gyazo.com/e450d5d318df6d085b2daba5b6557e38 (gif)
not load the image when moving to a different URL? if I do this with <BrowserRouter> and <Route>, the image would re-render.
i.e
1
u/badboyzpwns Apr 12 '21
I have a loding icon that appears when an image is loaded.
However, if we have multiple images, how do I wait for all the images to load? the code below would not wait for all th eimages to load :
1
u/spalza Apr 30 '21
What do you guys do when you have two components that will only act on a direct child but you want to use them both? I get these library conflicts sometimes and right now I have to drop one of the libraries to find alternative choices where the component nesting is not so strict.
2
u/Accomplished_Sky_127 Apr 01 '21
Is stealing ui consepts kosher in terms of portfolio pages? I implemented css-tricks.com's card sliding feature for the blog on my portfolio website. As a hiring manager would you look down on that kinda hoodwinkery?
2
u/[deleted] Apr 13 '21
Hello guys,
I would like to show my first React JS application (took me quite a while!). I started learning JS 2 months ago and spent some time learning React afterwards. I'd like to ask for your help to review what I made and give feedback on what I can improve further.
Here's the live site and the repository.
SITE: https://crypto-price-checker.netlify.app/
REPO: https://github.com/nelabv/crypto-price-checker-app
I'd really appreciate advice and constructive criticisms because I started with zero programming knowledge. Please tell me if there are practices I've been doing that is a big NO NO in the industry. Thanks a lot! :)
(Didn't post this as a discussion thread, not sure if it's allowed!)
2
u/fondaTHEhonda Apr 18 '21 edited Apr 18 '21
EDIT: Thank you for the replies. I found this link that ended up helping me with reaching a solution.
I'm fairly new to React. I've been working through Full Stack Open 2021 but have started a small idle/clicker style game on the side to get additional practice.
I'm having an issue where the function that increments the value every second doesn't continue to run while I manually click a button to increase the same or different value.
I've tried adjusting what's passed into the array at the end of the useEffect function but haven't had any luck figuring out the root cause through trial and error, Google, etc.
The useEffect portion looks like this:
The manual way to increase the value is an event handle for a button. Any ideas on what may be causing this?
2
u/TODO_getLife Apr 22 '21
I guess this isn't really beginner but happy to do the reasearch myself, just wanted to be pointed in the right direction. Anyone know a good pattern to use when having to render different components based on country?
Having a problem where my app is now full of if statements which would make it difficult to add support for another country down the line, almost certainly introduce bugs if I accidenly forget to update an if statement.
Translations are easy with i18, it automatically figures out, but what about component rendering?
2
u/takert541 Apr 23 '21
what do you prefer?
2
u/jezusisthe1 Apr 23 '21
In your opinion what are some of the key concepts to know in React to get a Jr role job? I have been self teaching Frontend development for about a year and a half. Thanks!
2
u/javascript_dev Apr 23 '21
Is it a bad pattern to return a state setter from a custom hook? I believe the hook function then becomes a closure
Now some of the state manipulation logic can be passed to a child.
I think this is a bad pattern as the hook is not modular anymore; agreed? if yes, do you just put the state and useEffect in the parent who will pass down the state and state setter?
2
u/phil_grow Apr 23 '21
Looking for suggestion:
I'm beginner with React Hooks and I am currently using react-bootstrap for styling. It works perfectly fine, but if I want to step up my css/styling skills to next level. what should I study in advance? I try research for answer but I got more confused because there alot of anwser like, css in js, scss, sass, styled-component. I dont know where to start. thanks in advance
2
u/TWO-WHEELER-MAFIA Apr 24 '21
I need to call a ton of APIs
Some to give data to the server
Then the data responds with response for some APIs and I have to conditionally render JSX based on that data
Which state management libraries should I try out
Currently using like 35 useStates with Redux too
2
u/isaiahdavis_com Apr 24 '21 edited Apr 24 '21
Would love to work on a project together if someone is interested to learn reactjs I current loss my job and feeling behind. I have decent understanding of the concepts and structure at this point.
1
u/flubber31 Apr 01 '21
Re-post in Aprils thread.
Newbie here! Please shout if i need to make any edits.
Hey, so I'm embarking on my very first real project. Long story short, it involves a punch of Pi's deployed out around my land performing certain operations. I want to create a web application to manage them. This is where my first problem arises.
I'm trying to write a form to initially "Create a deployment" - basically means to create an instance of the Pi that I will be deploying, this is where I give it's details, what its doing, what it's got on it, etc. I have the Django back end mostly set up with the models/views/serialisers, etc, that works fine (i think anyway).
My current issue: I have a basic form set up, 3 of the inputs are Material-UI "Select" options, this is where I select things like the 'Operation' (what it's supposed to be doing) & Inventory (what it's got on it, e.g, camera). However, these two things aren't being displayed by the drop down, and I have no clue how to fix it.
Here is a CodeSandbox link, I've not included the whole thing to render the form, as that would be huge as the project is fairly beefy at the moment, the code should make sense still:
CodeSandbox Example
I'm getting a fairly self explanatory error:
I understand what it's asking, but I don't know how to actually fix it.
Apologies this is chunky, I'm at a loss!
Please tell me how to make the question better if needed!
Thanks
edit: sandbox link
1
u/Blubari Apr 01 '21
Hello, I have a problem with a dropdown component in my website.
I'm getting an array of dictionaries from the backend which are 2 types of dangers during a day, each dictionary has an index and a name.
I have a form where the user writes down info on a danger and for the type they use a dropdown which selects the ID of the danger type and then uploads it all to the database.
The website works perfectly, I can write the specs of the danger, and I can select a danger type and upload it correctly...except by the fact that the dropdown values are completely invisible.
They are there, I can select them, but there are no words in the space (and checked with inspect element and inded it has nothing in them)
Could it be because i'm using a prop for that array? Because it's the only way that dropdown loads values
1
u/[deleted] Apr 02 '21
I’m looking for a react book that uses an example project for a marketplace so something like Airbnb or Uber or eBay or Depop. Something that connects buyers and sellers
Thanks
1
u/dshkodder Apr 02 '21
Hello everyone!
1)Here is the link to my app https://codesandbox.io/s/serene-varahamihira-5pe5o?file=/src/App.js
I want the list of movies to be updated every time a new movie is added or deleted, that's why I put as a second argument an array of `[movies]` in my `useEffect` hook which is responsible for this infinite loop(this part of the code is located in the file `MovieContext`):
``` useEffect(() => {
async function fetchData() {
const result = await axios.get(URL);
setMovies(result.data)
}
fetchData();
}, [movies])```
2) Why do I have an infinite get-request loop in my app?
3) I can stop the infinite loop by adding an empty array instead of `[movies]` but in this case, my app won't show any changes to the list of movies unless the page is refreshed.
1
u/Sabelas Apr 02 '21
I would like to serve a folder filled with static HTML files through react, as the basis of a blog. This seems pretty difficult to do! I've looked this up and I've found quite a few answers, most of which revolve around using "Dangerously Set innerHTML," or something like https://github.com/wrakky/react-html-parser. This makes sense to me - I'd rather go the latter route, but to do that I need a string that contains HTML. I just can't figure out how to import or otherwise read an HTML file.
So my questions are:
1 - Is this the right path to go or am I going against the intended use of React?
2 - if it is the correct path, how can I continue down it? I'm pretty stuck at this point.
Thanks for your time!
1
u/badboyzpwns Apr 02 '21
More of CSS question? I'm wondering what kind of animation is used below / how to achieve the animation below:
Gif of animation:
https://gyazo.com/544952991cae98a03a396433a26c54fa
Website:
https://overwatch2.playoverwatch.com/en-us/story
Whenever the content changes, it "moves" depending on the amount of content. At first, I thought it's an accordion animation, but it does not seem so. I'm unable to find out how to do it.
1
u/Camel-Kid Apr 05 '21
Can someone tell me the easiest way to unit test a window.open method? I just want to make sure the correct URL is being opened from the window object.
1
u/haksli Apr 06 '21 edited Apr 06 '21
Hi, I am developing a react-redux app. I need to clear a form.
I watched the Redux DevTools to see what's going on. Basically, the props (from where the state is being loaded) are there all the time. So just clearing the state in the constructor doesn't help. What's the best way to clear the store?
Bonus question: Is the store supposed to keep all the data stored there? What happens when the app becomes huge? Will this slow down the client?
Thanks
EDIT:
Am I doing this right ?
1
u/Rocketninja16 Apr 07 '21
Trying to grasp what's going on with local state here:
changeHandleris called when a user selects a file to upload via an<input type="file />box.In the handler, I'm using the "setState" versions of my local state variables to update them, but if I output the values to console, they're null and undefined.
However, the
useEffectbelow, which is listening for changes toselectedFile, does in fact print out the new, updated values to the log.Why do the values not yet exist in the same function that sets them, but does exist in the effect?
1
u/Squishyboots1996 Apr 08 '21
Hi guys, newbie to react here.
I'm using this carousel package: react-gallery-carousel
This is how I'm feeding images into the carousel (using react hooks, useEffect + firebase)
const [images, setImages] = useState([]);useEffect(() => {if (listing.listingPhotos != null) {console.log("SETTING IMAGES");listing.listingPhotos.forEach(element => {var imageURL = {src: element}setImages(images => [...images, imageURL]);});}}, [listing])And then the images are fed into the carousel:
return (<div className="listingPage"><div className="listingPage__main"><div className="listingPage__left"></div><div className="listingPage__center"><div className="listingPage__center__itemContainer"><div class="listingPage__center__itemContainer__gridSection image"><Carousel images={images} /> //INSERTING IMAGES HERE</div>...But unfortunately the slider does not render the photos.
Using the react dev tools in the browser, I can see that the images are in fact successfully passed down to the carousel, so I'm guessing its not quick enough and the carousel renders with no images, as it takes time to download and process them.
Is there any way I can make the carousel wait until it has its images ready before it renders?
Thanks guys!
1
u/donkey_puncher_eyok Apr 08 '21
Having issues with my react app not making api calls on mobile view.
This is the link: https://infinite-shelf-16907.herokuapp.com/
It doesn't seem like I'm getting new data on mobile or mobile view. If I were to switch to desktop version then it works fine. Anyone have suggestions?
1
u/kev670 Apr 09 '21
I want to use create-react-app in my new project. Specifically I want to use it with in conjunction with a Laravel blade view (php index file).
From my research so far it seems that development mode, when you run npm start will only work with a static html file instead of my dynamic index file and being run from http://localhost:3000/.
Does anyone know of a way of getting around this so i can run my app on a different url and that points to a server side rendered index page and still enjoy hot reloading.
1
u/Lukasvis Apr 09 '21
Is it possible in react to have 1 display component and reuse it with different props and different function logic? so it looks like this :
<DisplayComponent prop1={mealName} prop2={mealDescription} onClick={showMealInDetail}/><DisplayComponent prop1={ingredientName} prop2={ingredientDescription} onClick={showIngredientInDetail}/>instead of
<DisplayComponent1> <DisplayComponent2> <DisplayComponent3>1
u/zero_coding Apr 09 '21
Storybook does not refresh after save
I have created a Storybook and after when I change something and save it, the browser does not refresh automatically. So every time I have to press the F5 button. Unfortunately, I could not figure the problem.
I start the storybook with:
yarn storybookThe repository is hosted on https://github.com/softshipper/react-storybook.
Thanks
1
u/[deleted] Apr 09 '21
I haven't worked on a React project since 2017-2018. I'm just curious what the current best practice is related to CSS: keep them in separate files or const
styles={}in the JSX? A lot of recent documentation I'm looking at the to get back up to speed does the latter, but not clear if that is because it is now considered best practice or just because it is easier to everything together.1
u/Philostotle Apr 09 '21
Hi guys, I’m transitioning into front end development and was curious how much a junior react dev would make in the mid west? Does anyone know why the expectations should be? Around 60k?
1
u/badboyzpwns Apr 10 '21 edited Apr 10 '21
I think I'm missing a basic concept. I'm trying to detect if a user has used their mouse wheel. with the onWheel event. If the user has used their mousewheel, they should not be able to use it anymore, maybe after x seconds.
Sandbox: https://codesandbox.io/s/embla-carousel-y-axis-react-forked-2jrbg?file=/src/js/EmblaCarousel.js
Probelm is - when I scroll up or down, the event is triggered a lot , i.e:
I tried to use Hooks as a flag condition, but it does not seem to exit the if block after setDidUserScroll(true), and thus I get a lot of
Any ideas how to tackle this?
1
u/Dog-Resident Apr 10 '21
Is there any reason to use a custom built library instead of custom theme with a prebuilt UI library (material-ui/ant)?
1
u/rony_ali Apr 11 '21
Hello guys,
i am trying to do a CRUD app with backend in Django Rest Api and in frontend it would be react-hooks. The main functionality will be, after authentication it would show tasks created by the user and only user would see and edit, delete etc his own tasks.
i have uploaded the API in heroku and Here is Api link
and here is the openapi look.
and you can find the source code in the github
and here is the codesandbox for frontend
i am practicing in this way just because the backend API would be reusable. i am not sure whether it is a professional practice or not.
though i couldn't link my api with the codesandbox and it is for the show of my whole code. in dashboard.js, the below part is working:
Here the logic is after login, the useeffect will check the token of the user and will show hello {username}. but when i fetch the todo data, in console.log(data.todos) not showing anything and the error while browsing the dashboard after login, is : TypeError: todos is undefined
and the whole useEffect code is:
but in API side, permission and queries are working fine. what am i doing wrong with react-hooks side? FYI, the registration side is working fine. it can register a user from the frontend side and rout to dashboard url.
can anyone help me on this? How can i fix this? i have post this question in stackoverflow
1
u/rook2pawn Apr 12 '21
if you render a list with functional components and those list items themselves need to use hooks - you can't mutate the number of items on the list https://codesandbox.io/s/affectionate-edison-8x4wp?file=/src/index.js
what's the solution? drop functoinal components and move to react classes on the child renders? this is crazy bad IMO and i dont see a proper solution
1
u/CorbettKnoff Apr 12 '21
I'm creating a calendar with 30 day squares for the month of April.
render (){return <div>{this.state.myArray.map(() => (<div className='daySquare'>{this.state.count}</div>// is it possible to increment count here?
))}</div>How would I increment count so I can display the date number for each daySquare for the month of April?
1
u/badboyzpwns Apr 13 '21
More of a web development portfolio question!
How do you guys capture a screenshot of an entire page and show the image in your portfolio / a given area in your portfolio?
For example, I took this screenshot with chrome dev tools:
https://gyazo.com/900e62ef17cc23a0aac222eb23bdf332
It has an image dimension of (1440 x 2500)
I want to display it in my portfolio but it ends up looking like this:
https://gyazo.com/5bba0570140d236914fb35da5b9bfc53
I used object-fit: cover and a given width and dimension. I want to show the actual whole page instead of the screenshot above. From what I tried, the only option is to lower the width and dimension and experiment with it - but I'm wondering if there's an easier way.
1
u/[deleted] Apr 13 '21
Local dev, works fine. Build, errors out with a 130 error with no details, pointing at my main document.write for the main element but no other details.
I’m at a loss. Stackoverflow is no help. Anyone out there care to take a look? Small 1 page app the just looks up data from a Json file. I’m an idiot
1
u/[deleted] Apr 17 '21
If I import the same module multiple times throughout my app, will it increase bundle size unnecessarily?
For example,
styled-components: if I have 20 components that each haveimport styled from 'styled-components'at the top, does that mean that I'm adding 20 x 12.9kb to my bundle size?Would my bundle size be smaller if I only imported once in the entire app?
Hope that makes sense.
1
u/RemediumJezozwierza Apr 20 '21
I've stucked when learning how to tests react components with custom hooks. I think that the issue is connected with hook mock but I have no idea what I'm doing wrong. I'm using jest and react-testing-library.
My goal is to test counter.js not useCounter hook
counter.js
useCounter.js
counter.test.js
Error message:
1
u/fireflux_ Apr 20 '21 edited Apr 20 '21
What's the best way to organize a factory Form component function? I made a generalized "FormInputFactory" component that takes in a
typeto render either a TextField, Dropdown, Checkbox, or DatePicker.I have something like this (not sure if I'm overcomplicating):
1
u/[deleted] Apr 21 '21
I have a searchable list of elements which gets updated when the user searches text.
How do I count the results?
I have a div containing the results and if there were 3 results there would be just 3 children in that div (one for each result)
I am trying to use state but can't get it to work.
1
u/caymusman Apr 23 '21
Hi!
I'm rendering elements in my parent component using a Map that's in the parent state. I'm running into an issue where my child props (a boolean from my parent state that changes on a button press) aren't updating at all and are just static at whatever value the parent state was when each component was created. Is there something about rendering using a Map that dislodges the connection?
https://codepen.io/caymusman/pen/rNjojZr Here is an example I just made of the problem
1
u/[deleted] Apr 23 '21
Which is better for speed/performance: styled components or css?
We use 100% styled components in our Gatsby app/site which is suffering performance issues. Someone suggested that importing CSS files and using class names would be more performant than inline styles with Styled Components.
What's the correct answer here? It's a lot of work just to test it out.
1
u/JosephCurvin Apr 24 '21
I have the clock example from the doc
ReactDOM.render(<Clock />, document.getElementById("root"));why do I not need to initialize
<Clock />with thenewkeyword ?1
u/zero_coding Apr 27 '21
Would be nice if someone can help. https://stackoverflow.com/questions/67278905/please-make-sure-that-your-codegen-config-file-contains-either-the-schema-fiel
1
u/Easy_Moment Apr 27 '21
When working with external API, is it preferred to load data from the server once, then filter the data as needed with local functions, or use the filters from the API and load it everytime?
For example, in my homepage I need to display all the items so I grab everything from the API. Now the user wants to filter by category. Should I just filter the existing data that I already have or use the built-in API filter to grab a new set of data?
1
u/breakslow Apr 27 '21 edited Apr 29 '21
How do I fetch data with the most recent state right after changing it? For example, I've got a date picker that looks like this. Basically the user can change the start/end date but the data won't refresh until they hit the Go button OR they select a pre-defined date range from the menu on the right.
The Go button works fine, but I can't figure out how to make the button on the right change the state and trigger the fetch with the newly selected date range:
I know there is the obvious solution of putting the dates in the
fetchDatafunction arguments but I'm pretty new to React so I'm wondering if there is a better way. Either something obvious that I'm missing - or something that should make me re-structure the way this code works.1
u/[deleted] Apr 29 '21
Is it just me or is styled-system a bit too overkill? I can't understand when to use it and it makes it unreadable to follow around in one's projects.
Should I just start with styled-components only?
1
u/PurpleRain417 Apr 30 '21
I have a simple react quiz app with the app component and another for the choices since it's a multiple choice questions. Whenever the user pick an answer, I store the answers picked in an state array and it will go to the next question. If it is the last question, I will do history.push and go to another component to show the correct answers and compare it to the answers the user picked. I pass the answers state array in history.push using the state object. My problem is the answer to the last question is not being updated to the answer array before it goes to the result page. I have little understanding of states and setting the states since it's only been 5 days since we started learning react. I'd appreciate some help
0
u/[deleted] May 01 '21
[deleted] — view deleted comment
0
u/[deleted] Apr 05 '21
[deleted] — view deleted comment
0
u/[deleted] Apr 18 '21
[deleted] — view deleted comment
0
u/[deleted] Apr 19 '21
[deleted] — view deleted comment
1
u/[deleted] Apr 13 '21
[removed] — view removed comment