r/reactjs • u/acemarke • Oct 30 '17
Beginner's Thread / Easy Questions (week of 2017-10-29)
Looks like the last thread stayed open for quite a while, and had plenty of questions. Time for a new thread! (I should probably consider labeling these as monthly or something :) )
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
3
u/iTipTurtles Nov 07 '17
Thinking about getting Road to learn react Is this a good starting point, or are there better alternatives?
2
u/Kenpaachi Nov 22 '17
Any body have a good article on how to handle client side routes? I mean, not ow to use ReactRouter but suggestions on how many levels should u go and that kind of stuff.
Also, do you guys treat EVERY state of ALL your components in Redux? Or do you have "Smart Components" that handles states but are not connected to redux ?
1
u/[deleted] Oct 31 '17 edited Oct 31 '17
I'm using Angular 4 with RxJS and ngrx/Redux but would like to try out React.
The reason is simply because the Office Fabric Components look promising. This would make further development much easier.
https://github.com/OfficeDev/office-ui-fabric-react
However the React tooling is a major pain in the a**.
If I'd make a requirement list it would be:
Is there an easy way to integrate all that into the application? I've used the Microsoft TS starter kit and failed. Also is there a way to abstract WebPack like Angular does?
1
u/VaSs0 Nov 03 '17
When do you need a constructor in your class? I thought I should always initialize state inside a constructor, but I'm watching a tutorial where the instructor uses
this.setStatewithout it.1
u/[deleted] Nov 05 '17
Best Resource to learn Redux?
1
u/jackwilsdon Nov 06 '17
I'm looking to dispatch an action when another action happens in Flux, or at least do something similar. I am dispatching a
USER_LOAD_ERROR, which I need to listen to and then re-dispatch as aSHOW_ERROR_MODAL(with some changes to the data). I could listen forUSER_LOAD_ERRORactions in myModalStore, but I don't know if this is the best option (especially considering I'm going to end up with lots of*_LOAD_ERRORaction types).I've written my problem up in a bit more detail on SO.
1
u/[deleted] Nov 21 '17
I'm assuming this is a common-enough issue that's been resolved numerous times.
I'm using the Container / View pattern described in this article: http://lucasmreis.github.io/blog/simple-react-patterns/ and I have a section where I'm calling array.map() to create a list of data entries. I keep getting the warning "Each child in an array or iterator should have a unique "key" prop."
Now, I've done this many times before but never using this particular design pattern (I typically just mush it all into a 'mixed' component with no concern for separating view and logic). I've always included the key. The dataset that the entries are based on all have uids coming from the database and I was happily using those as keys previously. I've tried assigning this value as the key in as many different places as I can think of and I keep seeing this error.
Sadly I cannot actually share any of the code as I'm at work and the policy regarding code sharing is very explicit (don't do it). So I won't be doing that. Instead I am hoping to poll the gurus here and see if they are:
For what it's worth the app appears to be working just fine, but I fear that I'm inviting problems later as this list can, ideally, be edited on the fly and entries may be deleted, and as anyone who's tried using bad keys in such a situation probably already knows you can see things that are most unexpected when you can't rely on your keys (the classic 'array index as key' trick, awful if you're expecting to delete items from said array).
tldr where do i put this fracking keys so I quit getting console warns :(
1
u/[deleted] Dec 01 '17
Just started learning React and understand the concept of components and props, but have gotten a bit stuck on state. I know they are like props, but different. What are they and when/why would you use state instead of props? Thanks.
3
u/[deleted] Oct 31 '17
Also, would you be more likely to hire me if I had one app with a small community of users or three apps that are well on their way with useful bits of code but not yet useful for production as a whole?
1
u/Awnry_Abe Nov 15 '17
I am looking for redux store shape suggestions for an entity model that is about 4 layers deep from outer-most model to inner-most. Entities do not repeat, and are fetched from an API that more-or-less returns them one layer at a time given the parent id. Here is a pseudo-structure:
EntityA { hasMany(EntityB) } EntityB { hasMany(EntityC) } EntityC { hasMany(EntityD), hasMany(EntityE) } EntityD {...} EntityE {...}
I am still at the noob stage and am following the pattern in the redux async and have the first two layers wired up. But the training wheels are getting wobbly as I try to bolt the rest on. To get the list of B's from A out of the store, I use
const { entityBs } = state; const Bs = entityBs[idForSomeA]; // is an object with async state + an array of items[B1, B2..etc].
What I have seems broken in that the name-value pairs are keyed by the parent id.
I did briefly look into redux-orm, but I am not ready to bite that learning curve off just yet. At this point this app is a toss-away so I can get my arms around some of the react & redux fundamentals. Thanks.
2
u/vv1z Nov 03 '17
Curious what folks are using for deployment patterns? Is a simple express server the best solution? Anyone scale this using AWS/Azure/etc?
2
u/cegal Nov 13 '17
Hi folks, a bit late to the party.
A bit of background: I'm practising with Flask + React in this repo.
Here is my issue on SO.
But I figured I could ask you guys, in a more general sense, what are the heuristics when one wants to pass variables from the server side to a component at the first rendering of the html template:
Thank you very much in advance,
any advice is appreciated
2
u/artAgent Nov 20 '17
I'm looking for any good examples or articles for migrating from a BEM style SASS setup to SASS with react components, preferably while using create react app. thanks
1
u/roessera Nov 14 '17
Is there a server-side equivalent to componentDidMount() ? For example:
1
u/[deleted] Oct 31 '17
I'm working on an open source Firebase + React web app. Ideally I would like to have the development code up on a GitHub master branch and the production build on gh-pages, both so everyone can see live updates and so they can reuse (parts of) the program.
I've done this and it works all well and good, except that my Firebase configuration information is completely public and therefore my own site is completely insecure. Is there a way to keep only this information private on GitHub? I haven't upgraded my GitHub account because my impression is that GitHub offers the service of keeping entire repositories private, which is not what I'm looking for.
1
u/kvothe9114 Nov 01 '17
ive been stuck on this pokedex app im making, its coming along really well but i need help on displaying images dynamically in a loop in my Formfield.js file. source code can be located here: https://github.com/Nicholas-Rotondo/pokdex/tree/master/src/app so far i can display everything but images. only issue is in Formfield.js but if you want to look around in my app feel free. any help is greatly appreciated!
1
u/vv1z Nov 04 '17
Anyone have an open source analytics solution that they are really happy with? PO is looking for better insight on our app usage but unwilling to pay for a vendor solution...
1
u/Aromano272 Nov 06 '17
Can't seem to get eslint with airbnb config to cleanly install and run.
I created my project with create-react-app, after it finished i do
./node_modules/.bin/eslint --initand choose Airbnb's style guide.It doesn't recognise my import path to react, neither does 'npm start' work anymore.
EDIT: I saw 2 locks files because i was running yarn mainly, but eslint --init seems to run npm, so i started from scratch using only NPM, and this issue seems fixed, but now I have the same problem as below.
If i create the project with create-react-app like previously but instead run the install script in https://www.npmjs.com/package/eslint-config-airbnb :
Everything still works but i get some warnings :
Definition for rule 'jsx-a11y/href-no-hash' was not found jsx-a11y/href-no-hashHas any1 experienced this before and how to fix it?
1
u/senaps Nov 08 '17
hi all,
1- how would i lift state up? we are toughed that props are not to be edited or changed, and then we pass one to a component and get it's value back? :| i need a very simple explanation on it!
2- how am i going to get the whole page? okay i know how to create a message box, the login form and stuff, but how would i create all of the page?search box in this side and those post in other side, login button up in the top? should i make an html file and have just part's of it rendered by different components or should i try to learn to make the page in a index.js file that renders the whole page?
3- i have my login thing, i send an api request to the server, they return me with an login success or wrong cred's thing. but im unable to get my hand's on the result.(that is returned back to me, i just can't access it!) here is the code for that: https://jsfiddle.net/kqvj7na8/ in developer's tools i have successfull login thing, but how can i assign this value so i can check it? or get a token that is passed to me and resend it with every next request?
1
u/Kenpaachi Nov 14 '17
In react-router v4 there is no onRender handler for Route Element. How r u dispatching actions for stateless components rendered on Route?
1
u/sonnytron Nov 15 '17
I'm having a serious issue that's bothering me a lot when using create-react-app with gh-pages.
I am on develop branch.
I spend a lot of time adding code, making changes.
My .gitignore has only one file in it, ".DS_Store".
I finish my changes, commit, push and now develop is more or less where I want it to be.
I switch to gh-pages, merge develop and... My public folder is missing. It's just gone.
It's almost like the gh-pages branch doesn't want to merge the folder in.
I spend hours fixing it by copying files from develop to a flash drive/external folder, switching back to gh-pages and adding the files, forcing mergetool to use the new local shit, or even completely deleting my gh-pages branch and forcing it to develop.
And then I run yarn deploy and my gh-pages branch gets fucked up again.
Why does the gh-pages script modify the local folders? It shouldn't do anything but deploy the completed build. It shouldn't be modifying my files in any way.
It's seriously turning me off from React.
Has anyone stumbled across this? Is there some option in package.json that I'm supposed to set that tells the build script to leave my stuff alone?
1
u/Awnry_Abe Nov 18 '17
Redux: Calling selectors in mapStateToProps => When to destructure?
When calling a selector in a container, should the entire shape of the state tree be hidden from containers, looking like this:
or should the selector be ignorant of what subsection of tree it lives? like this:
I've flip-flopped back and forth on the virtues of both and have settled on the first form, but I wanted to see what is normal. My reasoning is that selectors are part of the store ecosystem, and should be aware of its shape. Containers should be agnostic towards its shape. Ultimately, something needs to know about the shape.
1
u/Ralliare Nov 21 '17
I'm looking into moving my work to react though I've not had that long to get my head into it. I do have a few questions I just can't get good answers for. Most of my googling just turns up a node package or 3 year old article so I can't get a grasp of what is accepted or "good practice".
1
u/2girls1up Nov 23 '17
Hello, I am an absolute beginner and I have to do a project for university where I have to use React. I decided to go with the Bootstrap design of CoreUI.io. Everything worked fine so far and I was able to implement what ever I needed from the documentation. Now, for the first time, I can't implement something and I need some help:
I want to implement one of these bootstrap collapse elements but when I do so, the element doesnt work. Instead of collapsing, it sends me to the frontpage. Any Idea what I could be doing wrong?
All I did was copying the code from the documentation and pasting it basically into my code.
1
u/Jolio007 Nov 24 '17 edited Nov 24 '17
Hello, I'm struggligng to get quotes from an API : / I read countless ressources. When I try to implement it, it doesn't seems to work. If someone could enlighten me. I have made a code pen page thing here - https://codepen.io/jolio007/pen/aVGNor EDIT : got helped by someone to solve the problem but could anyone explain to me how it works. For example, I'd also like to get the author name
1
u/vamsi_rao Nov 26 '17
Hi, I have recently shifted to web development from mobile development, and I have to admit that I am really liking it. Even though this is not react specific, I wanted to know how search is carried out in a webapp. If you could explain it from frontend to backend , it'd be really helpful. I also wanted to know how autosuggestions are shown while typing the search term.
1
u/prove_it_with_math Nov 27 '17
I have created a login page for the user and I'm not sure how to redirect the user to the dashboard after successful authentication. In other words, how do I route the user to the subsequent page on certain actions?
1
u/vladmuresan02 Nov 28 '17
I will be out of town for a few days, going back to my parents house.
Since i'm away from my main pc (don't have a laptop, opted for a high end gaming pc, so it's kinda stuck in one place) i would like to continue learning and experimenting with react.js on the pc i got there which is a old Athlon, 512 MB RAM XP machine.
Can i install node.js and NPM and start developing on react on that machine? Also, if i can, which version i can install? Thank you.
1
u/IvarBjorn Nov 28 '17
I want to render some components in my existing webapp. What components should render, and where they render is decided at runtime.
So I have created a solution using create-react-app and I am including the output bundle.js in my webapp index.html. How could I pull a component from the bundle and render it?
1
u/mrbinky3000 Nov 28 '17
I'm updating my project to use React 16.x. However, I use Jest with Enzyme and Enzyme requires that I upgrade to Enzyme 3.x and it has issues. Anyone here successfully made the transition to React 16 + Jest + Enzyme 3.x?
1
u/SonicViewBob Nov 29 '17 edited Nov 29 '17
Hi, I started to learn React recently by working on my app. I want to have a drawer that would contain navigation menu, and be toggle on click on a button and shift content of the page. So far I have 2 pages(components with other components, not sure about terminology) and my drawer with working router. all works and look almost like I want aside of one thing. I don't understated yet how to pass state from drawer that it's opened or closed to page, so it would adjust its width accordingly
i'm using "react": "15.3.2" "material-ui": "0.19.4"
my app.js looks like this
and the drawer has a function to toggle it
I have one global css file in by bundle with 2 classes app-bar and app-content that should work for open and closed state. I tested it by putting page content directly into drawer component and it worked; the only question is how to organize this state flow between components to modify the look of it, and pass data in the future
thanks for your help, guys
1
u/Peng-Win Nov 29 '17
I'm making an HTTP req and saving response to component state. I'm calling the method in componentDidMount(). However, I get the following error:
Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the component_name component
I thought componentDidMount() did wait for the component to mount? How can I make an HTTP req before rendering the component (the component is rendered based on the response)?
1
u/Dream_Penguin Nov 29 '17
Just started React the other night and never before have I gotten so much power out of each line of code.
1
u/gigobyte Nov 29 '17
I want to migrate react-router v3 to v4 but the shift in thinking is not to my liking. The main new feature of v4 is that you can use the Route component everywhere and the docs encourage you to put Route components in your views and layouts which I don't like at all. I want a single routes.jsx file which contains a declarative configuration of all routes in the app, not Route components spread out through the whole application. Is this achievable in v4?
1
u/sam_walker210150 Nov 30 '17
Hi guys, new here. Also very new to react (started last week). Currently making a react front end prototype for my app, using material-ui. It needs to download a specific file on the click of a button, but I can't seem to find any examples of how to do this. Any ideas?
Thanks!
1
u/prove_it_with_math Nov 30 '17
In ES6, when do you import like this:
import { someModule } from 'someLibrary';And when do you import like this:import someModule from 'someLibrary';1
u/prove_it_with_math Dec 01 '17
process.env.NODE_ENVis undefined. Where should I initialize the environment? I've tried to do it using webpack and I've also tried initializing it in package.json with thestartscript. But neither method has worked.1
u/2girls1up Dec 01 '17
Helo, I am a react noob and i am looking for a easy to implement timeline framework. I couldnt find anything so I would be really thankful if somone could help me out
1
u/Peng-Win Dec 01 '17
How do you run a React app on a server? I'm currently doing npm start and opening up the port to public. Is that it, or is there a more complex procedure for this?
0
u/wilkesreid Nov 12 '17
What can React do that VueJS can't? Is it just a matter of which you prefer? I'm able to be incredibly productive using Vue and Vue-router, vuex, etc. Is there a measurable benefit to using React over Vue? The only reason I can think of right now is React Native, since Weex and NativeScript Vue aren't production ready.
0
u/[deleted] Nov 14 '17
[deleted] — view deleted comment
1
u/[deleted] Nov 18 '17
[removed] — view removed comment
1
u/[deleted] Nov 21 '17 edited Nov 21 '17
[removed] — view removed comment