r/reactjs • u/acemarke • Jan 02 '18
Beginner's Thread / Easy Questions (January 2018)
Based on the last thread , seems like a month is a good length of time for these threads.
Soo... 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.
The Reactiflux chat channels on Discord are another great place to ask for help as well.
26
Upvotes
2
u/[deleted] Jan 03 '18
React n00b here. I’d like to make an API call and store the data in a component’s state but only render the component after a response has been received. I also want to update the component’s state with data from an API call after a user clicks s button. Using setState within ComponentWillUpdate triggers an infinite loop. So where is the best place to make my API call?
4
u/bramthebird Jan 23 '18
Hi all! I've wanted to learn React for quite some time and wanted to know what would be the best approach / resources to learn it. What would you suggest? :)
My background: Basically a designer with a bit of front-end understanding (HTML / CSS / JS). Uni courses have taught me some other languages (Java, Processing, Matlab, R, little bit of SQL) so I have some 'experience' with programming overall.
Intended approach right now: freshen up Javascript skills, then dive into React. Want to do both via paid online courses at Codecademy, because they allow me to write code directly in an editor and automatically give tips and check if the code is OK. Do you know if their courses are high quality or would you recommend looking elsewhere?
Also, I've had the idea of creating my own markdown editor for personal use for a while and would like that to be my first React project! Do you think I should 'hack' it together using already available React components (fast MVP) or code from scratch for educational reasons?
Finally, are there any other things I should definitely look into? (e.g. Node, NPM, REST; complete newbie regarding this stuff..)
Many thanks in advance!
1
u/forcedUsername209987 Jan 02 '18
Ill start I'm creating a form in react.
I have a drop down component that consists of a text input and a list of divs. I would like to fire an event onblur of the parent component, however onblur bubbles up and fires when leaving the text input child component which has its own own onblur function.
I have a similar issue with another component that has an onclick action on a button element that fires when I press enter on any input element on the form.
I've tried using stopPropogation and preventDefault in the event handler but no luck.
Can anyone point me in the right direction to finding out what's wrong or how I could debug this issue.
1
u/[deleted] Jan 03 '18
Is it possible to send setState as props? Is it considered bad practice to do so?
1
u/Gbyrd99 Jan 03 '18
Is there and easier way to manage forms and what input has been sitting at. Instead of listening on onChange events?
1
u/casebash Jan 03 '18
The React docs say that multiple setStates may be batched together, so you shouldn't rely on this.state when creating the next state.
However, in the tutorial we wrote:
In particular, is
xIsNext: !this.state.xIsNextactually a bad idea?What about
const history = this.state.history.slice(0, this.state.stepNumber+1);? It seems like if the previous one is a problem this should be a problem too.Does this mean that the whole function should be wrapped in
this.setState(function(prevState, props) {}?1
u/wabsky Jan 04 '18
I would like to make a real-time whiteboard/drawing application with socket.io and react. What do you think about that? Maybe using react in this particular situation is a none-sense?
2
u/shuraman Jan 11 '18
How can i convert an already existing div element with its own child element to a jsx element? for example:
<div class="parent"><div class="child"></div></div>would translate to a jsx element2
u/WeMeetAgainAdrian Jan 18 '18
So I have an array of objects on my state and while adding and modifying objects in that array works fine, removing seems to be giving me some troubles.
I've been trying multiple ideas and all of them are giving me an error where React can't find the object to render (even though the object being deleted isn't rendered) .
Right now I've come up with this, but for some reason this creates a new object outside of the array rather than modifying the array, what's there that I'm not seeing?
Does the fact that the array changes and so the position of the elements in it also changes force react to re-render everything? And since the index is different that could technically be a different object.
2
u/i_am_hyzerberg Jan 22 '18
in a larger scale React app, how do people usually manage bundle size with webpack? Is it common to create several different bundles with different entry points so that your bundle sizes don't get out of control?
2
u/sparkletastic Jan 22 '18 edited Jan 22 '18
I'm brand new to React and just beginning the process of rebuilding my site in React. It's currently mostly in PHP with a little JS for hiding/showing menus, etc.
The current site has 1 core page that pulls content from a large PHP array that contains the copy for about 3 dozen landing pages, which go into image galleries (which I don't develop or maintain - all I do are the landing pages). (The PHP array contains ~5 sample images and ~5 paragraphs or <dl>s of rich content; there's enough content that most people would probably use sqlite or something, but, because of reasons outside of my control, I can't use SQL.)
What's the best way to approach this? I converted my PHP array into JSON, but I haven't been successful in getting React to actually get into the JSON (unsuccessfully using Axios, per some stack exchange posts). I don't mind reformatting or reconstructing the PHP array content if that's the best way to approach it - it's just in JSON because that's what I know.
But I feel like I'm conceptually approaching the site incorrectly - the more I read, the more I think React shouldn't be treated like a JS version of PHP.
How would you React Masters approach the project?
2
u/daVinciLe0 Jan 31 '18
I've been working with React for a little while now and I've got a question on the mindset shift involved in building web applications in React. I've been working in web development for about 8 now and feel like I just got it drilled into my mind from the community that you always always separate your HTML, CSS, and JS and now I find React challenging me on the preconception all the time. So far I feel like I'm doing a good job of being pretty open to the change in thinking and am trying to stay aware of my own biases but I'm so curious if other people are battling with this too? A pretty good example of a specific topic I'm going back and forth on right now is my layout. I'm going to use CSS Grid to lay things out, now I could create a grid container and item component in React and have them all over the place in my JSX, which also adds a lot of extra wrapper elements essentially to the DOM. Or I could just do my layout in one CSS file.
So I guess I have two questions.
One, are others, or have others gone through a tough time changing their way of thinking and being OK with going against many of their learned "best practices" to fully embrace React? Do people still care about that separation in any way?
Two, thoughts on layout with CSS grid, keep that in one css file or create React components to handle it and keep it all in the JSX?
1
u/VYKTOR27 Jan 03 '18
So I've been trying to make a simple app. I'd like your feedback & how would you approach it. The page has three components. First component is a format selector, where you can choose MySQL or CSV. Upon selecting any one of those, you get a form where you upload the given format file. In the second component, you are able to see the source of what you uploaded & the last one is a visualizer. In that we have drag & drop functionality which gives us some buttons where we can join the tables taken from the csv or MySQL schema & display it in a sliding pane. We can also order it. Now my approach is pretty simple, make separate view components for all. While uploading the MySQL or csv, connect it to a database preferrably MySQL running on node backend. Then display the schema in second component & for the visualizer just do simple SQL.queries and render it. Yet I'm still not able to understand from where should I start. I started with the view & got stuck at uploading CSV file because I didn't understand how I should save that CSV data to MySQL server. Arghhh, guys just let me know if you can think of an easier better approach.
1
u/Gbyrd99 Jan 04 '18
If you're leveraging a UI library. Should you even bother writing tests for them?
1
u/yamfun Jan 06 '18 edited Jan 07 '18
Suppose I was marooned on an uninhabited island or just released from prison or kidnapped by aliens for years, and only know about non-web DelphiVCL/Winform/WPF/XAML/hurrrrr-html1.0-br-tr-td-head-body-...etcetc, so I know nothing about js/css/DOM/reactjs/c#-webapi/frontend/backend/fullstack/client/server/REST (so many of them omg) yet but want to learn it now.
What I want to know are, the name of things in the webdev world that are already obsoleted before I had even heard about it, or things that are less likely be used at the same time with reactjs/c#webapi, so that I can uh, prioritize not googling about the irrelevant stuff? e.g. I shouldn't need to read about those many older versions of asp, angular 1, jquery... right? (But then knowing the old way helps make you appreciate the advantage of new way so, I don't know) (edit: wow this link is what I mean https://hackernoon.com/how-it-feels-to-learn-javascript-in-2016-d3a717dd577f those "oh we don't do that now anymore" part)
And what are stuffs that I hadn't yet listed that I should know? (because many reactjs articles assume some prerequisite knowledge and I am quite lost now)
1
u/WeMeetAgainAdrian Jan 06 '18
Suppose I'm making a search function with auto complete where results come from a database. Do I build the text box with all possible results from the get go or make ajax calls to the server as the user types? Neither solution seems optimal.
1
u/[deleted] Jan 07 '18
I want to make a simple web note app like simplenote or evernote (but with minimum functionalities) i was thinking of using the mern web stack. is this a good choice or should i use something else?
1
u/kRkthOr Jan 08 '18
How do you "publish" react/redux/node web applications? I have a react/redux webapp with webpack and a separate node rest service. How do I go about putting this whole thing online? I am so lost :/
1
u/prove_it_with_math Jan 08 '18
How do I reset select-option state after form submission?
1
u/[deleted] Jan 11 '18
Is there any way to make an embeddable widget from my form component I created?
1
u/su8898 Jan 11 '18
What would be your recommendation for a react-redux-webpack boiletplate to get started with actual development? I am setting my eyes on marvin. Thanks in advance.
1
u/etzinho Jan 12 '18
I was working with python3/Django and now I'm moving to a frontend framework, probably React.
Is there any good style guide (like PEP8 for python) on JavaScript/React? Or even for TypeScript/Angular
1
u/HashRocketSyntax Jan 12 '18
I'm taking a React Native course next week. I don't know JavaScript, but I do know frameworks like Rails/PHP. What JavaScript tutorials should I do in order to ramp up?
1
u/brokennoses Jan 17 '18
Hey guys,
Building my first couple of react apps, only been coding Javascript for a few months and could use a little help.
I am trying to understand setting state and rendering - I'm wondering why my changeName() function doesn't successfully update the name and render it to the page.
In the course I am taking, the instructor uses a similar call in this code, the line this.videoSearch("surfboards");: - I don't see how this is different to what I am doing. Can someone please help me to understand?
https://github.com/StephenGrider/ReduxCasts/blob/master/video_browser/src/index.js
1
u/renshenhe Jan 25 '18
What's the best approach to calculating the width sum of mapped children? I'm currently considering
document.querySelectorAll('.item-identifier')which isn't very react but works so far. I could pass the ref of the children usingref={this.props.passRef}but not sure on how to accurately calculate the sum of the width of the entire list.1
u/ifydav Jan 28 '18
Is there a way to collect email, name, and phone number during sign up using firebase.
1
u/AllynH Jan 28 '18
Hi there,
I'm looking to learn some React to build out the front end of my web application. I'm interested in creating an inventory management system and I'm looking into Drag and drop for React (but I'm not having much luck working through the tutorial).
Is there a list of recommended tutorials?
I'd be particularly interested in creating an interactive UI with drag an drop capabilities.
1
u/Seus2k11 Jan 29 '18
Learning React currently - coming from more than 4+ years of AngularJS / Angular development professionally. Am I correct in that for most of the apps I'd encounter in the wild, this setup knowledge would suffice:
I'm looking to build out my next app with React and will use create-react-app as the beginning point for it, i'm assuming that it already includes Webpack v3?
Am I missing anything else that i'd need to bring in for my app to function properly with a RESTful backend, or to deal with states/routing/types/etc.?
TIA!
1
u/DaniSenpai Jan 30 '18
Been looking to learn how to implement authentication on React and Auth0 seems to be the way to go for most articles. Is this the case in practice? Or are there other/better alternatives?
1
u/AllynH Feb 01 '18
Hi all,
I'm working through the React Drag and Drop tutorial and having a few issues. I was hoping someone here might be able to make sense of them.
I've most of the tutorial completed but the board doesn't seem to be rendering properly, I believe this is because my CSS isn't being applied. I'm guessing this is because the author is using Flexbox and I've never used this package before. Also - how do you get React to recognise the styling I see the author has the styling in a Board.less file but adding it to index.css isn't working.
0
u/[deleted] Jan 31 '18
[deleted] — view deleted comment
0
u/[deleted] Jan 03 '18
[deleted] — view deleted comment
0
u/[deleted] Jan 09 '18
[deleted] — view deleted comment
0
u/[deleted] Jan 16 '18
[deleted] — view deleted comment
0
u/[deleted] Jan 23 '18
[deleted] — view deleted comment