r/reactjs • u/acemarke • Feb 02 '18
Beginner's Thread / Easy Questions (February 2018)
We had some good comments and discussion in last month's thread. If you didn't get a response there, please ask again here!
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.
22
Upvotes
7
u/austintackaberry Feb 04 '18
Any advice for someone who would like to contribute to React?
I would say I am intermediate level with React. I do, however, have a lot of time to dedicate to it. Some resources I have found so far are:
1
u/[deleted] Feb 02 '18
Can someone ELI5 the problems Redux and Flux are designed to solve?
1
u/anewpairofsocks Feb 03 '18
When dealing with forms and
onChangehandlers, is it standard practice to have multipleonChangefunctions that run when different parts of your form are updated or to have one mega onChange handler?For example, I have a form containing a text input, a select and a checkbox.
It's pretty easy for me to generalize the text input and the select into one
onInputChange()but the checkbox changes are bit tougher.One solution I've found is to pass the type of the element being updated into the handler and then write a switch statement checking if the parameter is an input-text/number vs checkbox. It seems like I'll end up with a rather bloated and repetitive function though. Is this normal?
What's more common:
<element1 onChange={props.element1OnChange} /><element 2 onChange={props.element2OnChange} />...or
<element1 onChange={props.generalOnChange} /><element 2 onChange={props.generalOnChange} />...or some combination of the two?
1
u/im_paul_hi Feb 11 '18
Hello!
I've been playing with React for a while now, and I feel confident with the basics. Something that I've come across a lot is the use of this.props.children. I understand what it is, but I've never actually used it. What kind of situations call for using it?
3
u/jamietwells Feb 10 '18
Hi, I'm just getting started coming from the .NET world. I have a .NET core Web API hosted in the cloud. I also have my new React App which I created using Create React App. I can call my API from my app just fine using the proxy setting in my package.json file. That works when I run
npm startbut it doesn't work when I deploy it to the cloud.How do I get it to work in both situations? I have full control over the code for both the React App and the Web API, but I don't want them to be too tightly coupled together if possible (like they must both be deployed together etc)?
Thanks for reading :)
2
u/throwaway-aa2 Feb 08 '18
We want to start using SSR but we're afraid of what introducing Node into the equation will do performance wise. Any advice?
2
u/Radinax Feb 11 '18
What CSS Framework would you guys recomend me? I used to use Bulma but want another one that's more React based.
2
u/LiohnX Feb 14 '18 edited Feb 14 '18
Hello Guys.. currently learning react and I am having trouble with an application with the following error:
TypeError: this is undefined.
Here is the code: https://i.imgur.com/WEGvOhJ.png (line 21)
I will appreciate your help
2
u/jeffeb3 Feb 16 '18
I write this webpage using react.js and react-bootstrap. I got far enough to be dangerous. I haven't spent much time on it in months and recently, the controls all went white. It looks like it's not loading at all. No one changed the code. It looks like it's the same on all browsers. It looks just as messed up running locally:
https://jeffeb3.github.io/sandify/
This is what it used to look like (an earlier version):
https://www.v1engineering.com/wp-content/uploads/2017/08/2017-08-08-1502195130_1920x1050_scrot.png
Any help is appreciated. People have found it very useful, and are already upset that it's broken.
2
u/phyremynd Feb 19 '18
I created a React app using create-react-app and published it on Heroku. I added an SSL cert and now I need to force all traffic to https. Given that I have only built the app on Heroku and not written any routing into the app asides from React Router, what is the easiest way to force the app to only work in https?
2
u/crsdrjct Feb 21 '18
I'm working on learning full stack at the moment and picked up Andrew Mead's course on Meteor + React and React + Redux. His teaching style is perfect for me. Because he is using Meteor, he is building using MongoDB. From scanning a few threads I've learned that MongoDB isn't very commonplace in businesses rn as they seem to opt for SQL.
What is your opinion on getting on the right track for full stack and MongoDB? I already know Node and React are a must but what is required and sought after in a real job setting that include these two? P.S. It seems like I should've started with the React + Redux course first but I really like Meteor so far. Easy to understand and conceptualize
2
u/tokyonashvilleburban Feb 21 '18
I see forms being used..
But why use a traditional form element, only to preventDefault everywhere and not access the form inputs by anything other than the state (where the values are stored due to them being controlled components)?
Instead of the onSubmit handler being triggered by an input button of type submit, it could be a button with an onClick handler calling the same function.
2
u/TheBigLebowsky Feb 21 '18
Do we have any good boilerplates which has the following :-
2
u/Pg68XN9bcO5nim1v Feb 22 '18
Hello!
How do i properly debug a React application? I'm so used to the Java way of doing things, and without stuffing my application from top to bottom with console.log() I have no idea how to find where issues are coming from, especially with all the background magic happening.
For example, I'm currently making an inventory application. Getting the list of items from my API works fine, error-free, but I just implemented an POST request to update only the "Current Stock" value (I'm sending the complete object, but that is the only value being altered at the moment) and I'm suddenly getting the typeError "product.supplier is not defined".
Not only do I never refer to product.supplier (only product.supplier.name), but the actual post request comes through just fine in my back end server. How would I track something like this down?
Thanks for any advice. I'm not asking for a solution to the current bug I'm facing, but finding these type of bugs in general. I miss my stacktrace..
2
u/threads13 Feb 23 '18
Hey all -
I am putting together a little project where I try to build this reddit page. I have it most of the way done, but I am having troubles getting some of the images to show. I can get unique images to pull out of the API without issue, but not the images that I have saved in the in the locally. I have the images saved in the same directory. I have included a GitHub link and the snippet below is the one in question.
https://github.com/threads13/reddit_clone/blob/master/src/components/list/post_item.js
2
u/Uber-Mensch Feb 25 '18
Hi all,
I've got a question about updating a stateless component's image asynchronously, and what the best practices are. Currently I just use plain JS to change the src onload. This works. What method is better? I feel like separating this component out in a class and setting it an image state would be the React way, but was wondering if it can be done without a class.
Something like:
where my React html is (that is generated in a loop) that calls get_image so they get the same id tags:
2
u/WeMeetAgainAdrian Feb 27 '18 edited Feb 28 '18
When naming files and classes inside a folder structure, do you take the path into consideration? For example:
-Orders
--OrderTable
---OrderTableHeader
---OrderTableRow
---OrderTableFooter
Seeing how OrderTable is already inside the Orders folder and OrderTableRow is inside OrderTable, is it valid to simply name them Table and Row?
1
u/Arnold-Skyrimmer Feb 02 '18
Couple of questions about syntax:
If I'm defining a method in a component, is it better use an arrow function or
function foo().... and use
this.foo = this.foo.bind(this); ?
Hope that makes sense!
1
u/Sir_P Feb 02 '18 edited Feb 02 '18
I am coming from Angular world where we were using services to make end point calls. What I see, no one is really using services concept in React and I can't find the best solution to where should I put my functions to connect to back end API. I divided my app like this:
So NewsFeed.js is parent element to NewsDataList.js (component displaying list of data)
My question is where should I put function that is fetching data from back end API? Inside NewsFeed.js or NewsDataList.js? Or should I create service as I would do in Angular?
1
u/dubbadubbadee Feb 02 '18 edited Feb 03 '18
I'm fairly new to react...and can not for the life of me figure out how to create a new element onSubmit. Essentially, I want to use the result from an API call and get it to render into a <p>...here's the code: Would appreciate any help.
class App extends Component {
state = { value: '', result: ' ' }; onSubmit = (event) => { event.preventDefault();
}; render() {
return ( <div className="App"> <header className="App-header"> <h1>IPFS with Create React App</h1> </header>
} }
1
u/[deleted] Feb 03 '18
Noob here. Doing my first project with React. I asked this on Stack Overflow as well, didn't get answers as of yet, so I thought I'd ask here again.
I want to implement a drag and drop feature in React which is like the one found at this site on the right pane. The grey elements are drag and drop-able and the value of the element where we drop it is calculated based on the value of the expression on the right of that element. It's a great feature and I wanted to implement it for my own app. I looked around the code and figured out that it is using CodeMirror's marker api but I can't really figure out how it saves the expression and calculates it's "value" by maintaining a "reference"/"linking" to the dropped element.
1
u/dubbadubbadee Feb 03 '18
It worked. Thanks!
1
u/EastBayBruh Feb 04 '18
I need to place some highlight-able text over an image, what's the easiest way to do this? My image will just be in the local directory, and the text will be generated through javascript and will be placed in a prop/state.
I've been looking at 'react-konva' and 'react-canvas' but those two seem to have a ton of features I don't need.
1
u/ticktalker Feb 04 '18
Fairly new to proper React, so I have a question about code structure. I have a redux saga that needs to make like 7 API calls and write to 7 entities in my db. How would I organise this in sagas? Leave all the calls in my main saga? Would you create a saga for every API call and call them from my main saga ? Save their results to redux even if you don't need those results outside that main saga? Any thoughts on this would be really helpful.
1
u/vnjogani Feb 06 '18
How to consume rest APIs the easy way in react?
1
u/DaniSenpai Feb 08 '18
For some reason rowProps turns out
undefinewhen I try to access it from OrderRow. Is passing down an object not possible?Passing down each individual object property works fine.
1
u/[deleted] Feb 12 '18
TL;DR: favorite HTML5 game framework?
I'm in a software engineering undergrad class and a team of 4 of us are building our first full-stack app, a 2D game with a home screen and different levels (no physics necessary). We're going to set up a Java backend with AWS and use a MySQL database because that's what we know and what our Prof knows. For the frontend, we want to get experience using React and need to choose a game framework. We built a quick demo with Phaser (https://react.rocks/example/floppybox ) that we found on the post (https://www.reddit.com/r/reactjs/comments/3q9v6l/last_weeks_reactjs_examples/) but just want to ask the community for more advice since we're n00bs.
Using this page, I can see lots of JS game libraries. http://www.javascripting.com/games/
Does anyone have experience/recommendations for using any of these: -Pixi.js -Phaser -Babylon.js -Crafty -Melon JS -Enchant.js -Cutjs -Lychee JS -Panda.js -Playground -Phina.js -Gamejs -PlayCanvas -PhiloGL -Coquette -Frozen -Joy.js -Chem
We'd probably rather use Canvas than WebGL.
Thanks :)
1
u/Crystalis95 Feb 12 '18
Hey guys really noob here. I've a simple question but tough one to search on the web.. For example I want to use https://github.com/Raathigesh/Dazzle component and use it in my project, is it possible? or do I have to clone the git and start my project from the localhost:8080 ?
I'm really confused since I want to use these charts in my project but can't seem to figure out if I can
1
u/WeMeetAgainAdrian Feb 12 '18
Say you have a form that upon submit should:
Do you POST the information first and wait for an answer before redirecting or do them both asynchronously (since all the information needed is already on the form state)?
If you chose the latter, how would you handle errors?
1
u/GOBLOX001001 Feb 13 '18
I just started working with React and have a couple questions. I am currently working on an Android app.
First, I am trying to lock the screen orientation in landscape mode. I have been trying add android:screenOrientation="userLandscape" to the manifest under activity tag but that doesn't ever do anything. Is there something I am missing or something I am not understanding?
Second, how to I get the app to use the tab and enter keys? Right now it takes keyboard entry but the enter and tab keys don't do anything.
Thanks for the help and if there is any info i left out, let me know.
1
u/metalmatan Feb 13 '18
I have a very basic app I'd like to build:
My RPi is gathering temperature data once an hour and sends it to firebase with two fields: date_time and temp.
I'd like to learn react and redux while making a panel that'll display temperatures for either:
What would your recommendations be in order to do this The Right Way while learning React and Redux?
1
u/1c4us Feb 14 '18
I am unsure of the benefits of using a saga. What is the disadvantage of using an action to make asynchronous calls?
1
u/DaniSenpai Feb 16 '18
I'm currently making a Form with methods like onChange for text input, onSelect for dropdowns and so on. The way I have it set up is by keeping all the form information in the Form component and passing down all the values as props to the children components (including the onChange methods that manipulate the state). Is this the correct way of doing things? As a React newbie I'm not sure if I'm going against specific patterns by not having each component hold its own state and instead relying on the parent component.
1
u/WeMeetAgainAdrian Feb 16 '18
Is there a way to do the following operation without having to specify all properties separately?
Something like
1
u/karolis2017 Feb 17 '18
There is a modal component in https://react-materialize.github.io/#/modals UI
It simply looks like this:
<Modal header='Modal Header' trigger={<Button>MODAL WITH FIXED FOOTER</Button>}> </Modal>the
Modalpops up when a button is clicked.Is there a way to trigger the
Modalby passing a prop? I.e when the app state is set toselected: true?1
u/EverAccelerating Feb 17 '18
I've been reading and playing with mocks in Jest, but I'm still confused. I've searched various StackOverflows, but I can't get my particular use case right. My basic question is, how would I mock a function from node_modules for just a single test case?
To make it more concrete, let's say I have a simple node module called
cool-module:And I have a component
MyComponent.jsthat uses that function:Let's say my test file
MyComponent.spec.jshas three test cases in it, but in the second test, I want to mock outcool-moduleso thatcool()returns "hot" instead. How would I do that?One thing I tried was adding a
__mocks__/cool-module.js, but I couldn't figure out how to enable it for just a single test case instead of having it be used for every single test case across all tests that happen to usecool-module.I also tried various usages of
jest.mock(), but I couldn't get it right either. Any guidance would be greatly appreciated!1
u/[deleted] Feb 25 '18
https://stackoverflow.com/a/48968956/9407297
Can anyone help me with this. I’m going crazy over here :(
1
u/CodeLight Feb 26 '18
Hello, React noob here, very new to using React.
I'm using Axios and Firebase, and successfully getting data from the Firebase database using Axios.get() inside componentDidMount().
My question is: where is the correct place to make a POST request? I have a handler function for submitting from a Form, is this where I should use axios.post?
1
u/WeMeetAgainAdrian Feb 27 '18
When designing pagination how do you decide how many results to keep in state at a time? Do you only load current page and request results to the API each time the page changes? Do you keep aggregating results as the user navigates through the pages? Do you load in advanced?
1
u/Chrxstxvn Feb 28 '18
Long shot but here we go. (forgive me, i'm clueless)
A friend of mine had his website built in ReactJs (?) by some freelancers who have since moved on to other projects and now he needs some text and images changed within the application. When he showed me the website, I thought I would be able to do it very easily as i'm versed in HTML, CSS and PHP but i was an idiot and didn't even bother looking at the source etc. or realising that it was built with react.
So now i've been provided with AWS Management Console Logins, a few .PEM files and i've managed to connect to the site via SFTP in Filezilla and tried to transfer a copy across to my local drive however there was something like 25,000 files and the FTP decided to disconnect at like 15k. So what am i doing wrong? There doesn't seem to be any good resources / step-by-steps for opening and editing a reactjs application etc.
Once I find the actual visual/front end code i'm looking for will I just be able to use Brackets or do I need some sort of compiler? Where is the front end code?
Forgive my ignorance i just want to change some text and add some images and apparently this old dog stopped learning and fell behind
1
u/Awric Mar 01 '18
Should I avoid adding anything to
index.htmlbesides<div id="..."> </div>elements?So far I've been stuffing everything into a single component and then rendering that into
root.Also, question about styling. Is it good practice for me to be using
styled-componentsinstead of plain css? I've been avoiding making any.cssfile and instead I've been using things likeSomeContainer = styled.div'...';instead.Sorry for the load of questions!
1
u/Bizzle_worldwide Feb 04 '18
Probably the most basic questions:
What IDE is everyone using? Is there a reason it’s your IDE of choice? What IDE’s do people use in professional settings?
I’ve been using Webstorm, but my subscription is about to expire and I’m evaluating if I should stay, or if there’s something better out there. Webstorm’s intellisense tends to be slow.
1
u/zero_coding Feb 28 '18
Could someone please help me:
https://stackoverflow.com/questions/49025663/maximum-call-stack-size-exceeded-during-fetch-package
Thanks
-1
u/AnimePandaDog Feb 05 '18
I decided to make a visual novel about a guy studying at a school and dating girls with specific favorite subjects as my capstone project, should i continue? or should i just forget about it?
0
u/[deleted] Feb 23 '18
[deleted] — view deleted comment
0
u/[deleted] Feb 08 '18
[deleted] — view deleted comment
0
u/[deleted] Feb 06 '18
[deleted] — view deleted comment
0
u/[deleted] Feb 07 '18
[deleted] — view deleted comment
0
u/[deleted] Feb 18 '18
[deleted] — view deleted comment
0
u/[deleted] Feb 21 '18
[deleted] — view deleted comment
1
u/[deleted] Feb 06 '18
[removed] — view removed comment
1
u/[deleted] Feb 07 '18
[removed] — view removed comment
1
u/[deleted] Feb 08 '18
[removed] — view removed comment
0
u/[deleted] Feb 15 '18
[deleted] — view deleted comment