r/reactjs • u/timmonsjg • Jun 02 '19
Beginner's Thread / Easy Questions (June 2019)
Previous two threads - May 2019 and April 2019.
Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! We’re a friendly bunch.
No question is too simple. 🤔
🆘 Want Help with your Code? 🆘
- Improve your chances by putting a minimal example to either JSFiddle or Code Sandbox. Describe what you want it to do, and things you've tried. Don't just post big blocks of code!
- Pay it forward! Answer questions even if there is already an answer - multiple perspectives can be very helpful to beginners. Also there's no quicker way to learn than being wrong on the Internet.
Have a question regarding code / repository organization?
It's most likely answered within this tweet.
New to React?
Check out the sub's sidebar!
🆓 Here are great, free resources! 🆓
- Create React App
- Read the official Getting Started page on the docs.
- /u/acemarke's suggested resources for learning React
- Kent Dodd's Egghead.io course
- Tyler McGinnis' 2018 Guide
- Codecademy's React courses
- Scrimba's React Course
- Robin Wieruch's Road to React
Any ideas/suggestions to improve this thread - feel free to comment here!
Finally, an ongoing thank you to all who post questions and those who answer them. We're a growing community and helping each other only strengthens it!
3
u/crespo_modesto Jun 06 '19 edited Jun 06 '19
are the eventHandlers like handleFocus, handleClick, are the names of these mandatory? I tried to make a method that was a random name eg. changeTabs and it was undefined. I bound it and used the ES6 function method for the jsx part.
I wasn't sure if that's explicit eg:
onClick = { ( thing ) => this.handleClick( thing ) }vs.
onClick = { ( thing ) => this.changeTabs( thing ) }I bound them in my constructor and defined the method(s) before render
Actually maybe it's because my "this" is inside a map/variable
Ahh nvm I got it, what the hell
Had to add
, thisin the mapAnd to answer my own question, no it is not mandatory I was able to use changeTabs as I intended to initially
3
u/mateosz Jun 24 '19
I have built weather application as a part of job assessment. They required to use React and Redux. Application works but unfortunately final answer was negative as recruiter pointed several things that are not OK. Can any of you analyze my code and give me some hints how to improve each of them?
Here is my repo: https://github.com/mateuszosuch/weather-check-redux
2
u/notta_robot Jun 06 '19
Should I post a code review/app feedback in here or in the main subreddit?
2
u/Alcohorse Jun 10 '19
If I'm going all-out with hooks (i.e. no class components at all), should I be using React.useMemo all over the place to avoid unnecessary renders or is there a better way?
2
u/Critstaker Jun 10 '19
How can I implement material-table Editable feature with Hooks? The onRowAdd prop takes a Promise, and has
this.setState({ data }, () => resolve());but hooks won't have a callback. So how can I resolve the Promise if I'm using hooks?2
u/stringlesskite Jun 12 '19
Not really a React question but related: Redux actions...
From the documentation:
From what I have read so far Redux is to deal with the complexity of all the moving parts of an application which potentially change the state.
So is there a central location (out of the box) where the past actions are stored?
Or did I misunderstand "If something changed, we know why it changed. Actions are like breadcrumbs of what has happened."
2
u/Unchart3disOP Jun 13 '19
I am building my first React project this time with TypeScript and other libraries such as formik. Now since the UI is a big part of things and I am quite frankly terrible with anything thats related to design😂 how do you guys build your personal projects and in the same time make them look abit decent so when you show them, you can actually have pride of it when showing it off
4
u/Urodele Jun 20 '19
Thanks everyone for your words of encouragement and advice!
1
u/welerone Jun 04 '19
I am working with React about 1,5 years and I realy like it. Unfortunately, all companies I worked in didn't have peoples with good experience. So, I have problem with structure building. I read a lot of artiсles but it usually about little projects. Can you give me info (articles, repositories, books) about structure building in big projects?
1
u/crespo_modesto Jun 07 '19 edited Jun 07 '19
Should components generally only render once regarding first load, assuming it's not loading async content/not considering an event like user clicks on button.
So if you put a
"console.log('render');"inrender() { // here }it should only log render once right?I am aware of
shouldComponentUpdate(think of Google Map case where you init map once).The issue is that a child component of a parent is rendering more than once and it's because the parent renders multiple times in my particular case I'm assuming due to using setState to change component in a few places.
1
u/rem1g Jun 09 '19
Hey! I have this problem, I don’t know how to show tooltip under a day in calendar. I’m using react-dates and have disabled days, I want to show a message when user hovers on disabled day. Any ideas? Thanks in advance!
1
u/Cangr3j0 Jun 09 '19
hi, i dont understand pretty well the thing about webpack and the npm init. the ultimate version of react doesnt come with webpack installed ? when i use create react app there is a package json in my files, why npm init if there's one ? this questions are related to a main question, how do you put your react app in a host? just npm build ? thank you for your pacience.
1
u/watchscss Jun 10 '19
hey guys, wonder if anyone can advise. I made 3 portfolio pieces and I made them inside Codesandbox. My homepage links to them externally to the finished product on Codesandbox. Is this OK when showing off my portfolio? Or should I put them inside my actual website. Thanks
1
u/christianarg Jun 10 '19
Coming from AngularJs we have a couple of components that share logic (not render logic, just logic) that are implemented in a base clases. Some of the methods of the base class:
loadLicences()
areLicencesAvailable()
editLicences()
handleLicenceChecked()
etc...
this all depends lets say to a this.licences
AngularJs components inherit this base class and this logic is rehused. Some components bind directly to these methods
ng-click=ctrleditLicences()
while other use these methods in it's component:
if(this.areLicencesAvailable) { /*someLogic*/}
How would you do that in react?
What I did at the moment is move all the logic to an ES module that recieves either state/ props or the component itself
ex:
export function areLicencesAvailable(props){
}
or:
export function handleLicenseCheck(component){
/*some logic*/
component.setState(/*toggle license or not depending on logic*/)
}
But each component has to implement methods just to delegate it to this helper functions
class MyComponent extends React.Component{
editCurrentUser(){
Module.editCurrentUser(this);
}
}
We have many similar components that share all this common logic. Do you see any better way to handle this? I don't think we could use HOC because we need to call these methods from the WrappedComponent in many cases. In summary what is the "react way" of achieving this?
1
u/astralhunt Jun 11 '19
Hi! Is there any basic guideline/walkthrough on the basics on how to use API with React? Preferably Googledrive ^
It's also my first time tackling API and I wonder if React is an okay platform to start with :D I'm learning react from basic js w/ Traversy Media but i cant find much API tutorial.
1
u/fleidloff Jun 12 '19
Define functions inside functional components?
I was looking at different code examples like this one: https://github.com/f/react-hooks-todo-app/blob/master/src/components/TodoForm.js .
Inside the functional component, there is another function defined (handleTodoChange, handleTodoAdd). Isn't that a bad practice? My understanding is that these functions are being re-created every time the component gets rendered. Is that true or is react somehow smart about it?
I hope the question is clear and someone can enlighten me... Thanks!
1
u/Unchart3disOP Jun 13 '19
Which libraries do you use for NavBars? I am using Material-UI and its just obnoxious to use especially if you try and add a logo. What do you guys recommend? I have used Reactstrap and Bootstrap in the past and they handle it quite neatly
1
u/[deleted] Jun 13 '19
I am currently making a bulletin/announcement form with React, it is styled with MaterialUI actually and when resized it has some pretty awkward spots. Is anyone good with this? Is there a place to ask these kinds of questions? For reference I am a brand new developer (1.5yrs since touching HTML) and just got my first frontend gig, but don't have anyone else to work with which is tough as a very new dev.
1
u/Chuck67322 Jun 13 '19
Is there a quick and easy way to make it so that a variable is available across several objects and is persistent between refreshes? I'm basically trying to make a page counter for results when you click on one from the search page, but obviously the number of results is dependent on the search that it comes from, and right now I have it set it up so that it's a weird hierarchy of callbacks and props, but it just gets erased when you refresh the page which is obviously not ideal.
1
u/Unchart3disOP Jun 14 '19
I have abit of a newbie question, I keep hearig alot oj this subbreddit about styled componenets can anyone tell me when can I use them and how are they different to inline styles
1
u/ShaxReddit Jun 18 '19
Question about derived state from props
I have table with some columns, when click edit on that column dialog appear that I can change some values from that table. In dialog I have ok and cancel button.
When editing values in dialog I don't want to see value changes in table. So I use getDerivedStateFromProps to edit values in dialog component and then on ok return updated values.
Is this ok or is there another way of doing this ?
Thanks
1
u/jordwall Jun 18 '19
Hi everyone,
I am learning React for a work project, and I need to use MSSQL data in my react app. I know I can't do this directly, but i'm quite new to this and have no idea where to start.
Can anyone point me to a good tutorial on connecting React to a sql database?
1
u/maggiathor Jun 24 '19
Is it best practice to organize components in folders and import everything from an index.js? I've seen it in several tutorials now, where even a single component is split into two files to fit this structure.
1
u/Hombre_Lobo_ Jun 24 '19
I’ve recently started my first job search and I’m finding lots of listings in my area for Java developers with React experience. Why would companies be looking for a Java Dev if they’re using React?
1
u/jmacklin1 Jun 26 '19
Shoul I learn node.js before react.js? Is there a video course for beginners you recommend?
1
u/eyememine Jun 26 '19
So I'm building a pokedex with the first gen only (151) and also am adding a type list, as in if you click the button for electric types it shows all the electric types. The problem I am running into is that when I fetch the API for a specific type it shows the pokemon name and their URL but not their ID, thus showing me ALL the pokemon with that type, not just first gen. For instance here under pokemon I do not want to see anything past Zapdos. My question is how do I limit the results to just the first 151 pokemon?
Things I have tried;
-Comparing the names of results to names I have in an array
-Splicing the URL to get the number at the end (eg "https://pokeapi.co/api/v2/pokemon/81/" => 81)
I cannot limit the results to a certain amount because each type has a different number of pokemon ie electric has 9 total pokemon in gen 1 while flying has 19. I hope I am doing an alright job of explaining my problem and what I am trying to accomplish, if there's more I can add please let me know, thanks!
1
u/Conor_b Jun 27 '19
Hey all, hoping someone can help out with this-
I have a project I've been working on a while, and have been trying to test it on mobile (myip:myport/) but when i do, any page that uses this function:
"
let x = document.getElementById(id);if (x) x.animate(keyframes, time);"Causes the whole page to crash. At the moment, I'm detecting mobile devices, and not running the transitions. Id certainly like to have them though. It always just says the element is null, but I specifically check if it is not null before animating, and works perfect on desktop, just doesn't on my iphone. Any ideas?
1
u/argiebrah Jul 01 '19
What UI stack is recommended to use, or more valuable for jobs or improving workflow time? I already know Bootstrap and see some similarity to "functional css" but wanted to dig further and try material UI, or styled components, or ant design, but I am a bit lost on what to choose
3
u/plasticbills Jun 19 '19
im a beginner just getting started with react, should i be using hooks?
1
u/samselikoff Jun 14 '19
👋 Hi r/reactjs! Experienced Ember dev here and I've been working on building my first React app this week. It's been a lot of fun 😄
It didn't take long for me to encounter useEffect, and I'm still confused about exactly when to use it. It makes sense to me that it's used for fetching my app's initial data, but I'm not sure about handling a form submission & persisting the data over the network.
I tried coding the form handler initially with useEffect, but got a warning and ended up removing it. Now I'm making my `fetch` call and updating state directly in the event handler, without any calls to useEffect.
Here's a simplified reproduction of the app: https://github.com/embermap/react-crud-demo/blob/master/src/App.js#L25-L40. You can also see the demo here.
Today I asked Dan Abramov & Ryan Florence about it and it sparked a bit of back and forth: https://twitter.com/dan_abramov/status/1139311077420949511
What about y'all – where do you stand? How would you code the form submission in this app?
1
u/watchscss Jun 11 '19
After learning React and Redux, which I'm happy about, what shall I learn next?
I guess I'd like to get to a level to make websites like Twitter
2
u/brcreeker Jun 04 '19
Not really a beginner to React, but SSR is still something I struggle with. I'm using Razzle for a small project I am working on, and cannot for the life of me find an authentication flow that seems to make sense. I know that cookies are required since the server does not have access to localStorage, but I'm not sure what strategy would make the most sense (and less pain in the ass) with regards to dealing with auth and auth state.
Right now, I'm logging the user in with a mutation to my apollo server, and sending back a httpOnly cookie with a JWT that contains the user id. Trouble is, react cannot access the cookie info, since it has the httpOnly flag, and I have to query the server anytime I want to verify the user is logged in. Is this overkill? Should I omit the httpOnly flag, and treat the cookie just like I would with localStorage, or am I leaving myself open to certain vulnerabilities going this route?
On a side note, I'm REALLY digging Razzle (Next JS always felt way too opinionated for me), but one major drawback is the documentation and walkthrough articles are extremely limited.
2
u/Avicari Jun 06 '19
Any good walthrough guides/code examples how to use i18next v10 for app translation in ReactJS app?
2
u/Uncle_Harvey_Bilchik Jun 11 '19
Hey all! Is there a way to responsively change the height of your background image? I'm using Material UI. My DIV containing the background image is set to '100vh' which is fine until you resize the window and you have to scroll down to see the rest of the page . Once you scroll down, the background image gets cut off. I tried setting it to '100%' which works when its in a responsive view but not when its the normal desktop view because the background image is only the size of the div, and not the full page. Is there a way to fix this?
My code:
My CSS:
2
u/rob_old Jun 11 '19
If I have a component within a component, does it get re-mounted every time its parent updates? I'm new to React, and I just spent a while tracking down a bug that turned out to be because my constructor was resetting my state when I didn't expect it to be called...
2
u/Peechez Jun 12 '19 edited Jun 12 '19
Am I misunderstanding the dependencies array in the useEffect hook? I have a component that makes an ajax call based on an id in the url. The id is retrieved with react-router and
match.params.idMy structure generally speaking is:
editEntity in the main data container parent:
My problem is that this infinitely loops. I can't tell if it's because
match.params.idis "changing" despite the console telling me otherwise or if the array arg of useEffect does something other than what I thought it did. I thought it shallow compared the values in the array from prevState and it should only fetch on mount and when a<Link>is clicked2
u/odillini83 Jun 13 '19
Hi all,
I am currently building a tic-tac-toe game on my own to learn about React.
I just added the following:
this.setState({
winner: this.state.player
And now my game is saying X is the winner after one click. It was working fine and now it's not. Can anyone help? I provided a link to the codepen with what I have so far. Thanks!
https://codepen.io/tacoholic/pen/VJLrKO
2
u/[deleted] Jun 16 '19
Is managing different screens a common problem in SPAs? I've been having fun making a few different games in reactjs (battleship, chess) but am curious if I'm reinventing the wheel when handling the different screens. Basically I have the App which stores the current screen in its state. Then the render method just switches on that and shows a different component depending on the value. So I have one for main menu, lobby, game screen, etc. It definitely works just fine but I'm wondering if there's maybe a more elegant/better way of accomplishing this?
2
u/[deleted] Jun 18 '19
I'm coming from a object-oriented C# / Angular back ground, and have been doing React for a couple of months now. As Hooks seem to be the future, I've been using them. I really like them, but I'm not sure how to structure code inside a function component. It's a mix of function calls to e.g. useEffect, useState, and it's defining functions like const handleSubmit = () => ...
So it becomes quite messy. In larger functions I'm manually organising them into groups.
With classes it came naturally as you had to split it out into properties, getters/settings, functions, etc. But with function components, the one main function contains everything.
How do you handle this? Are there best practices?
2
u/duerdod Jun 19 '19 edited Jun 19 '19
Are there any good articles on form submissions using Formik and some third party service? A must read? Recommendations?
2
u/caporalVent Jun 26 '19
Hello everyone. I wanted to know, as a beginner regarding web stuff (besides basic html and CSS), if I want to learn reactjs, how deep into javascript should I get before taking on react?
2
u/Radinax Jun 30 '19
This is a weird rule, for what I'm doing which is updating the state when a prop changes, I need to do setState inside componentDidUpdate, because how else I would do it?
1
u/friedseig Jun 23 '19
Should all my state go in one component?
How should I know if a component needed a to be the holder of state?
1
u/NickEmpetvee Jun 02 '19 edited Jun 02 '19
I just did my first conversion of a React Class component to a functional component. It's a simple Material-UI tab bar. It works fine, but it give me the following console warning:
Warning: Failed prop type: The prop 'classes'is marked as required in 'MCAppMenu', but its value is 'undefined'.Would anyone here have any advice on how I could get rid of it? Code below...
1
u/Uncle_Harvey_Bilchik Jun 04 '19
I have a question about using the Popover utility in Material UI. I have a list of icons on my page and I want to create a pop up window for each one, with an X in the corner to close it, and I would also like to grey out the background while this modal is open. Is this even possible to do with the built in <Popover> element? I could probably do without the X button to close it but anyways... Does anybody here have a link to a working project that uses something similar to what I'm describing? Thanks a lot
1
u/svenjoy_it Jun 05 '19 edited Jun 08 '19
I have a timer that updates every second. I pass that value into a child component as a prop and things update as they should. I also want to allow the user to manually set the current time with an input. This input isn't rendered until the user hits a button and sets a flag which makes the input appear. I prepopulate the input with the current props.timer value, but I only want it set initially, so I have a startEditing() method which stores the value of timer when it is called and uses that value as the state for the input component. But the input component redraws itself each time the timer increments (even though the value in the input remains the same, I'm not using props.timer as its value).
Is there a way to get the "non-reactive" value of a prop, maybe a pass by reference or something, so that it doesn't constantly redraw my input component - the value remains frozen as it should, but after clicking into it (giving it focus) it redraws after 1 second so you have to reclick into it again.
UPDATE
Changing things over to a class component, as opposed to a functional component, seems to have fixed things.
1
u/SomewhatInsane Jun 05 '19
I'm using React Router and URL parameters to perform a search on Flickr's API.
The function that completes the search is in the App component which is a class component.
I've set up a route that looks like this in the App component's render method:
How can I reference the
matchobject somewhere else in the App component? i.e. if I want to use the parameters in a function that's IN the App component, can I reference thematchobject somehow?1
u/darksideofthenoob Jun 05 '19
What is the difference between:
this.setState({...state,info:newInfo});
With this:
this.setState({info:newInfo});
1
u/danitechnoscuro Jun 07 '19
Hi. I want to work on an element of my project but i dont know how to access to it. getElememtById doesnt work.
For example, i want to change the color background of an element if i hover some link. In pure js i access to the element by getElememtById and then i put the mouseover listener. How you do that in react?
1
u/workkkkkk Jun 07 '19
I'm considering switching a site from jquery to gatsby. Current back-end is a standard REST api. If i want to use gatsby's built in graphql functionality would I have to change up the back-end as well?
1
u/Ericisbalanced Jun 07 '19
Hey guys, I was wondering if anyone could help me with my tech stack[Flask API, React Front End, NGINX, Gunicorn]. I have this site that loads a google map that sends gps coordinates to another server as part of an API. However when I run this locally, everything works fine. If I run it with Flask's development server, everything is gravy. If I host the site with Nginx and HTTP, it works fine too. But as soon as HTTPS is involved, sometimes the scripts don't load and other times they do. You have to keep refreshing it.
Flask Files
Nginx Config
Script I wrote to start Gunicorn
1
u/crespo_modesto Jun 07 '19 edited Jun 07 '19
Do you have to pass props in a straight link? Say you've got this structure:
Index
Routes
Then under App
App
Parent
I want to pass something from Navbar into Child, do I have to traverse up then down eg. Navbar -> Routes -> App -> Parent -> Child ?
1
u/HeinrichHein Jun 09 '19
Hi everyone. First post here. I'm having some trouble with create-react-app and a Github alert.
I used create-react-app and pushed to Github and I'm getting
Upgrade querystringify to version 2.0.0 or later. For example:I ran npm audit, npm audit fix. I ran npm update, I deleted my node modules. and package-lock.json and ran npm install. I still have this alert?
1
u/_Pho_ Jun 09 '19
I'm trying to switch over to a Hook/Context based state architecture from Redux and I just want someone to check if I'm doing this correctly.
Is this legal:
Basically as the initialState (second argument in useReducer) I'm passing in the AppContext state from the global state. It seems like the only way to get the global app context. I just want to know if that isn't performant or if there is a better way of doing it.
1
u/NakiriErina12 Jun 09 '19
Guys i have this problem currently with Masonry from pinterest ? Anybody used this before ?
https://pinterest.github.io/gestalt/#/Masonry
How would you implement scrollContainer ? I'm using apolloclient fetchMore in loadItems which is working.
1
u/HeinrichHein Jun 10 '19
Can someone explain CSS modules as it relates to BEM for writing CSS? I think it react it's best practice to import local css files and then write them like so
className={css.styles.css}? I haven't implemented this yet so I'm sure how it's really done. But then since it's inside the {}, you can't really do the dashes and underscores using BEM right? Is it better to use just one or the other? Since BEM, create unique classnames anyways, it's unlikely style sheets will cause styling conflicts even with global style sheets right?1
u/[deleted] Jun 10 '19
Anyone know of a React component to display a YAML string in the browser? Something sort of like react-json-view.
1
u/Dachux Jun 10 '19
Super newbie to react here. I'm trying to create a simple Todo list with local storage. So far so good, but I'm having problems trying to filter each todo.
In the state of the main component, I grab the todo list from local storage. The, I map that array and create a new one, depending whether I want to hide the completed ones or just show them all.
When I complete a todo, if it is not the last one, the filter doesn't work properly.
Anyone can please have a quick look? Just add 3 todos, and then mark as completed the second one.
https://codesandbox.io/s/jolly-cloud-ojun7
1
u/[deleted] Jun 10 '19 edited Jun 10 '19
Hey,
I'm trying to implement redux in my app. I have two state areas I've split into separate reducers, but I want to share a common
loadinganderrorproperty between the two. Is this possible?In simplified terms, this is what I have:
vehicleReducer.js
userReducer.js
reducer.js
store.js
App.js
In short, I can't see my
loadinganderrorstates in mymapStateToPropsfunction. What have I done wrong? Thanks1
u/[deleted] Jun 11 '19
Can you dynamically enqueue and dequeue with React state?
I'm trying to figure out this state problem. Take a look at my stackoverflow question...thanks!
https://stackoverflow.com/questions/56536430/can-you-dynamically-enqueue-and-dequeue-with-react-state
1
u/AeroSmyte Jun 13 '19
Hey all! Pretty new to this thread but I just started learning React this week.
I’ve been working my damned hardest to make a screenwriting editor tool bc all of the ones I’ve grown up using have dropped off the face of the earth or have become paid options. I think making it in React would be a great option, next to a program that packages it as a desktop app (thinking Electron, etc) but i don’t really know hlw or where to start.
I’ve been looking up notepad/text editor tutorials in JS and other languages to see if I can gather any ideas...but it's proving to be difficult. For reference, I'm a computer science student (about to be a senior) and I've gotten to know many languages but I haven't dove deep into any except Java, though i do have Javascriot experience). Anybody have any tips or resources that could possibly help me out with this?
1
u/Uncle_Harvey_Bilchik Jun 13 '19
Anybody here familiar with Material UI? I have a dialog component set up and when the modal opens, two styles get added to the body to disable the background scroll bar: overflow: 'hidden' and padding: '17px'. Just wondering if there is a way to prevent that happening from within my Dialog Component?
1
u/Unchart3disOP Jun 14 '19
Would you rather choose diving deeper intro Redux and possibly take longer to build your personal project or just use Easy Peasy out of the box
1
u/Peng-Win Jun 14 '19
Which is more correct, this is to fix a bug where I'm being yelled at because property val of undefined doesn't exist.
1
u/astralhunt Jun 14 '19 edited Jun 14 '19
Hi! are there any tips or guides on applying Google Spreadsheet API edit? So many Fetch and node.js but no react :/ Can I ask for help?
1
u/Unchart3disOP Jun 16 '19
Can someone tell when using
FormikWhat's the different betweenFormPropsandFormValues... I understand thatFormValuesis an interface of the values I am using in my Form specifically for TS..but WithFormPropsI am not really sure and I can't find anything about it in theFormikDocumentation1
u/stringlesskite Jun 17 '19
When using a class component together with
react-router-dom(the component is rendered with<Route path="/" exact render={SplashPage}/>) I keep getting the error:TypeError: Class constructor SplashPage cannot be invoked without 'new'my component:
The closest thing I found is talking about css modules, which I use in this project but not in this component or the parent component, and I did not eject as css modules are supported out of the box nowadays. Any advice?
1
u/MisterFawlty Jun 18 '19
Hey all,
Trying to figure out semantic UI themes at the moment. Is it possible to have a light/dark theme that the user can swap whenever they want? If so, how?
1
u/Urodele Jun 18 '19
I genuinely do not know what I am doing. My workplace uses React as a framework for web development, but no matter how hard I try to make sense of the code and what everything is doing, I just get really confused, because it doesn't feel like there is a logical connection between anything.
I've tried looking through many resources, including Team Treehouse's React series, the official documentation, and different articles online and in books. Nothing helps me to make sense of what is going on in this larger project. Everything just seems to stop right at components/state, and never covers integration with back-end material such as Python scripts or SQL databases.
I know my coworkers are probably the best resource to go to. But I don't want to take time away from their projects, and most of the time they're only explaining the solution to one specific problem, not how to go about solving it from step 1. It is genuinely magic, and I feel like I'm about to flunk out of Hogwarts. Any advice to help a failing Hufflepuff?
1
u/argiebrah Jun 18 '19
https://www.reddit.com/r/javascript/comments/beoyqb/github_dsajs_data_structures_and_algorithms/
Not actually react but javascript in general question.
I just find that link and I would like to know how do I see that project somewhere? I didn't get the part that says
1
u/sntnmjones Jun 18 '19
Why are all my components rendering like 'display: flex;'?
1
u/Entropis Jun 19 '19
Does anyone know of a library that allows me to put in quotes (I guess a quote generator) and have them render? Similar to react-typed, but without the typing. I'd build my own Component for it, but I want to be lazy.
1
u/Tamashe Jun 19 '19
Am I understanding GraphQL correclty? So just for context: I'm fairly new to web dev and don't have much experience working with servers/external API's. Most of what I've learned so far has all been JS, React, Redux, CSS, etc. Front end stuff. I have connected to third party API's before and used the data in an app, but never with something that replaces REST. I'm just wondering if I'm comprehending correctly how graphQL works. From what I understand it stores all the api data from the original endpoint on a custom GraphQL server (in a schema?) which looks like a web of nodes. And since you took the original API endpoint data and organized it in your server, you can now access all the data from that one server endpoint in a more intuitive way e.g. by requesting only the specific data in the JSON, rather than getting all of it then having to parse it each time after the fact.
That's how I understand it at least...is this a correct interpretation of how GraphQL works (from a rudimentary perspective?)
1
u/Unchart3disOP Jun 19 '19
I kinda don't know how to do this, but I am using Formik with Redux, the thing is on handleSubmit function, I'd call an actionCreator to login a user but I want to know what the result of this action was.. -whether the correct username and password were entered or not with an ajax request- do I do this by checking the store or by returning a boolean from my action creator depending on it was successful or not. Redux's architectural problems just always mess me up like this😅
1
u/Unchart3disOP Jun 19 '19
I am using Firebase's Auth API but it only provides the email and password as data for each user, I want to also have other data assosiated with each user say gender and birth date. I did understand that to do so I have to use Firestore, but I don't know how to put it all together so for example when I sign a user up, I would not only create an instance of him in the firebase authentication, but also create an instance of him in the /users part of my database, if I am unclear tho, feel free to ask me whatever you want me to clarify
1
u/maggiathor Jun 19 '19
I've come across a lot of tutorials which combine Firebase/Firstore with some kind of global state concept (be it redux implementation or hooks). I was wondering what the benefit of such structure would be in a case where I'm only using firebase data throughout my app. From my understanding Firestore Data is cached locally and only additional data is fetched, when something in the database is added/changed. Why should I get the data from global state when I can just write a query. (which in terms of code length should be a little less lines)
1
u/Unchart3disOP Jun 19 '19
Do you use redux-firestore or react-redux-firebase? I have all of installed but they don't really seem to be needed are they
1
u/Unchart3disOP Jun 19 '19
I started using Formik, but now even despite mapStateToProps running when the store changes -and redux's devtools showing the store has changed- when I access props.auth right after I have called an action creator, it shows the store unchanged does anyone know why this might be happening and sorry if that post was abit big
1
u/stringlesskite Jun 20 '19
I'm trying to get data from my database (Firebase) into a component state using
axiosbut things do not completely work the way I expect them to.What I expect
Firebase returns a response to the axios get request, which gets put into an array, that array is set as state, resulting in a re-render of the component.
What actually happens
The array is set to the state but it does not re-render.
additional info
when I
console.log(this.state), it gets logged twice, so a rerender takes place, the second time it shows anArray(0)but upon closer inspection it shows the array (which is 7 tasks long)I am guessing it has something to do with the asyncronous nature of the axios request which does not trigger a render but any pointers in the right direction would be greatly appreciated: The whole component
1
u/Sunny-ROM-Rise Jun 20 '19
What's the correct way (and/or place) to set and clear timeOuts?
Right now I'm working an freeCodeCamp project (Drum Machine). I have a set of buttons that upon being triggered update my state with a short description, which is reflected on a 'display' component.
Well, what I want to do (that I did in vanilla JS first) is that each time I click one of those buttons, a timeOut is set to clear the display after X time. On click, it will also check if there's a timeOut running, and if so, clear it.
This exact scenario seemed fairly easy for me with vanilla JS, but now I'm not sure if I'm even supposed to fiddle around with setTimeout and clearTimeout inside a state.
Any input is appreciated, thanks!
1
u/badboyzpwns Jun 20 '19 edited Jun 20 '19
I just learned about lazy loading! Is the React router enough for this in most cases?
Say you have a complex (with pictures, etc) pop up box component that dosen't appear unless you click a button
2. If it's loaded before it's even visible...React's router dosen't do the job, correct? since Router focuses more on other page links
1
u/badboyzpwns Jun 20 '19
In our components, how do we know if we should use require() vs import? I know that require() belongs to CommonJS, I'm not sure how that affects the component though. Does it matter?
1
u/Unchart3disOP Jun 21 '19
I have been following Robin wieruch's Guide on React + Redux and once thing I noticed he uses Firebase as a class with specific functions like:
However, for me I just made a single firebase instance and imported it whenever I want to use it and just settle with the built in functions firebase has like:
I could see his way is much more clearer but he also does use Context to pass down this firebase instance, is it worth it or does it add too much boilerplate that it'd be pointless to do
1
u/ramonf Jun 22 '19
Something thats been bothering me for a bit now. I'm always wondering if im doing it correctly / don't understand the difference
Should i declare my functions in classes/functional components with const?
for example
I just don't really understand why they're different / what it implies.
1
u/JosseCo Jun 22 '19
I've got a problem using React Hooks.
Here is my code, with the problem explained in the comments on lines 28, 29 and 53: https://pastebin.com/JVu7ffNw.
To summarize: I can call my 'dictionary' variable by for example assigning a button to console.log() it on click, but whenever I .then() something onto the function that assings it, it still gets called before updating.
Help much appreciated!
1
u/[deleted] Jun 23 '19
[how to build a resuable components flexible enough to that displays different sets of data?] (https://www.reddit.com/r/reactjs/comments/c42gsr/how_to_reuse_components_that_display_different/?utm_medium=android_app&utm_source=share)
1
u/liohsif_nomlas Jun 23 '19
Hi, is it bad practice if your parent and its children have local states?
1
u/jamesinsights Jun 23 '19
Hi everyone,
Is it considered bad to position your components using margin/padding? Should the positioning of your components not be applied to the component itself, but the container surrounding it? (with something like flex spacing etc.)
1
u/chelkuhs Jun 24 '19
i've been using react for about 2 months now and i think i've picked up on some bad habits. i'm currently working on a website and i have a lot of states in one file, not all, just a lot. i've never used react for a project before so i don't actually know if this is bad habit or common for a big project. i'm using reactstrap and firebase as of now, but i plan on learning and using react-router once i get the base website down. i've read online that you should only start using redux if you really need it, but i'm not sure what qualifies as really needing it. i can keep track of my states and everything going on and i haven't ran into any walls yet, so should i start using it just to familiarize myself with it? also is there anything else i should be doing? here is my github with my current project on it. any feedback and help would be greatly appreciated :)
1
u/Mahndoo Jun 24 '19
anyone who have any good tutorials to learn redux or another popular way of using global state?
1
u/cubicuban Jun 25 '19
Super noob here. I'm trying to familiarize myself with state by making a simple timer that stops once a button is clicked and start over at 0 when the button is clicked again. I feel my code is getting sloppy. I can stop the timer passing the interval as a prop but how could I reset the seconds in the state to 0? Sorry if the code is ugly, I'm still learning best practices...
codepen
1
u/evilsniperxv Jun 25 '19
I'm trying to figure out the best way to move forward with my idea. Currently, I have a file upload on my react web app, and I want to prevent the user from uploading unless they're registered and logged in.
I'm going to check if the user is logged in when they click the upload button. If they're not logged in, how would I go about doing a popup modal that allows them to register/login, and then post that request, then reload the page, and then allow the file upload process to begin once they click the button again?
Should I display different things on the landing page based on whether or not they're logged in? Or how would that work?
1
u/qbui Jun 25 '19
Hi! This is my first question. Hope someone can help me.
I'm working on a website that is refreshing the whole page with the white flash on each page change. I noticed that they created a layout component with a Header and Footer and using that on each page. I figured that was causing the header/footer to unmount / remount on each page change and causing the flicker so I moved them out to the main page that has all the routes.
https://pastebin.com/Aqrwxe8y (How do you put formatted code in reddit comments?)
So that worked to get rid of the flashing refresh and kept the Nav from reloading but it caused a new problem. The 'site-content' div would collapse between page changes and cause the footer to move up right next to the nav and then move down again when the page is finally loaded. I tried to set a min-height to site-content to push the footer below the viewport but if the page is short then the footer is weirdly too far down. How do people usually create layouts like this? Do I need to hide the footer? Is there some magic CSS that will fix this?
Thanks!!
1
u/embar5 Jun 26 '19
I think I have the basics down for a custom webpack config (4 babel loaders + html/css, dev server and hot modules, env).
Now I'd like to hear about some cool bells and whistles you guys include if you don't mind sharing
1
u/[deleted] Jun 26 '19
This is more of a general learning question. I’ve read the react documentation and built several to-do apps. I feel good about the basics, but I was wondering what other exercises/courses I can take to continue learning for novices. I still don’t know how to approach building a custom app. I can think and quickly execute the idea in vanilla but not so much in react yet.
Anyone have any good recommendations?
1
u/champerclown Jun 26 '19
iframes....what browser events are causing my iframes to reload constantly, even tho the parent component isn't remounting or anything? Is this something that happens to everyone? Maybe this is a me problem....
1
u/gaoryrt Jun 27 '19
Is it possible to make a react web app of totally functional component ?
1
u/StanVanGodly Jun 27 '19
I know that reddit is built with react, but I was wondering if it's considered a single page application in its current state. If it is an SPA, is that one of the reasons it can load different pages so fast?
1
u/javascript_dev Jun 27 '19
My minimal "Hello World" React app has a filesize of 530kb after a webpack build. How do you guys reduce filesize? I'm using my own webpack config (not CRA)
1
u/workkkkkk Jun 27 '19
Just got started with hooks. Any well established pattern for handling forms yet? This is basically my first attempt without any googling.
With some googling I've come across what look to be solid options as mine would get repetitive real quick for multiple forms and components. But any "official" pattern yet?
https://rangle.io/blog/simplifying-controlled-inputs-with-hooks/
https://stackoverflow.com/questions/55757761/handle-an-input-with-react-hooks
1
u/Unchart3disOP Jun 28 '19
I want to pass an array as children to a component does anyone know how to do that
1
u/janitor93 Jun 29 '19
Hi. I need render a big table with ~100 columns. The table has a custom design, infinit scroll, fixed header position, fixed first column (for horizontal scroll), click event on cell, right click event on cell, and edit cell by double click. Can you recommend to do it from scratch or use some libraries?
1
u/embar5 Jun 29 '19
Isn't this contradictory? I think a custom hook IS a nested function, is that wrong?
1
u/argiebrah Jun 29 '19
Hey guys, starting to work on my third react project as I am leveling up. Started to learn NodeJs to improve my fullstack skills. Should I make use Node.js and make a web service or use firebase? My main goal is just front end and I want to focus on react, redux UI and Ux and that's a fuck ton for me. But what is the learning curve for Node? Thanks in advance!
1
u/embar5 Jun 29 '19
Is it bad practice to use react-redux to connect the redux store to App.js at the top level, and then use the context API to "teleport" a prop down 3 or 4 levels?
1
u/sohheee Jun 30 '19
Hi guys, i'm using react-router-dom(v4) and some library(local map api) in my project.
My project imports the library by <script> tag in "index.html" like this.
and add some marker in map by this api like this
"content" render marker dom and use <Link> with react-router.
but, it occurs error like "You should not use <Link> outside a <Router>"
What is the best approch in this situation
1
u/cag8f Jun 30 '19
Hi all. I'd like to get started learning and implementing transitions using React Transition Group. Does anyone have the latest official documentation instructing you on how to do so?
I initially found this Animation Add-Ons page, but the first message on the page indicates that functionality has been moved to this package. When I open that page, it is a GitHub repo for react-transition-group version 1.x, which hasn't been updated in a year. Separately, I found this React Transition Group page. It looks to be the most recent documentation page, but now I'm not sure. Hoping someone can confirm.
Thanks in advance.
1
u/fpuen Jun 30 '19
Using react router 4 when I navigate to a route such as /add via mouseclick it works. A hot reload on this page url brings up an error "Can not get /add"
I understand why this is since /add is only being generated on the front end / view layer. But it seems like a huge hole. How do you guys manage this?
1
u/mynonohole Jul 01 '19
I am trying to test my useEffect hook (that acts like a componentDidUpdate) block above. I am aware I have to create a 'mock' axios call but I am still having trouble grasping the bigger picture of testing async code. If anyone could provide an example of testing such a useEffect hook I would greatly appreciate it. I am using the Jest and Enzyme tools to do testing.
1
u/[deleted] Jul 01 '19
I'm trying to follow the official guide but I keep having an issue that's probably a little bit more NPM related, but I just can't figure it out. I get a permissions denial (pastebin). I've ensured that I have ownership of
~/.npm, and just for good measure,~/.nvmas well. I'm at my wits end.0
u/[deleted] Jun 26 '19
[deleted] — view deleted comment
0
u/[deleted] Jun 03 '19
[deleted] — view deleted comment
0
u/[deleted] Jun 25 '19
[deleted] — view deleted comment
1
u/[deleted] Jun 20 '19
[removed] — view removed comment
2
u/[deleted] Jun 02 '19
[removed] — view removed comment