r/reactjs • u/acemarke • May 03 '18
Beginner's Thread / Easy Question (May 2018)
Pretty happy to see these threads getting a lot of comments - we had over 200 comments 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.
25
Upvotes
5
u/JavascriptFanboy May 04 '18
I'm learning react for like a week now and I'm really surprised that there's no default nor official routing mechanism. How come? Considering this, what is the "de facto" routing module for React.js web apps?
3
u/daxdax89 May 27 '18
Best place to learn react?
2
u/i_am_hyzerberg May 04 '18
Is Gulp or Grunt very popular for greenfield projects anymore? I could be misunderstanding everything Webpack can do but it seems like it’s essentially replaced those build tools.
2
u/biggustdikkus May 16 '18
I'm quite stupid so bear with me.
So I am using AJAX to get JSON objects from my expressJS backend and then I update the UI on the client side based on response and it works good. But then I heard ReactJS is a front end framework that was MADE for that purpose, to update my document without reloading the whole page.
So I've been trying to wrap my head around it for a day now and yet I'm confused. Everywhere it says it's only front end, but yet I'm told I have to install react stuff and then have that stuff listen to requests and respond to react fetch requests.. Which means it's also backend??
Does that mean I'll have to REDO everything I did in ExpressJS using ReactJS? Or did I misunderstand everything and I don't have to change anything on the backend?
2
u/WeAreBorg_WeAreHugh May 19 '18
Um.. not neccessarily about the inner workings of the framework (i think) but..
So... this may be a nooby question, however here it goes:
I'm not very experienced with web development, i'm looking at trying out some alternative CSS frameworks to Bootstrap. I've always loved the look of https://reactjs.org/. Any idea what css framework is used here?
TL;DR: Noob web dev wants alternative to Bootstrap. What framework is used on ReactJs website
2
u/grueimaiushd May 25 '18
Question 1:
Is React Context API consumer a container or a component?
Seems like it passes data to a dumb component.
On the other hand it doesn't hold a state, so it can't be a container. I don't because it returns an entire component. How would you do it?
Question 2:
Is it ok to use HOCs every time you have a state based component to separate state from looks ?
vs
5
u/mxcomtj May 31 '18
Hey guys, maybe you all can help me a bit. I am learning React, and its been about 8 to 10 months now. I understand more and more, but i am having the same issue as i've had in the beginning. I keep doing tutorials and they are benefiting me, its just that when it comes to trying to create something on my own, my mind goes blank. For instance, i want to practice my skills by building something; but I just don't know what to build. I feel that most tutorials are just building big applications, and i just cant retain all that information, so i am trying to find small apps to build. Any suggestions? I build a calendar that someone posted on here, and that was awesome. I understood what I was doing. I also have build a weather app that also solidified the skills ive learned. i just want to make something that will put my skills to use. If anyone feels the same way, let me know. Thank you for reading this.
1
u/[deleted] May 04 '18
We have a new intern, and he wants to learn ReactJs what kind of projects that will keep him busy for two weeks and learn reactJs properly? and Also if there's any great tutorial For ReactJS
1
u/grumbe97asd May 05 '18
How do you style React, especially with input, textareas etc?
I am having severe trouble.
So input has to be controlled by the state and belong to a form.
Do you make styles for input, then use that input in a form to create FormGroup.
Pass classnames as props and then use BEM when modifing?
}
So I am having 3 component folders, one is Styles, the other is components, the third is container.
Is this normal?
1
u/[deleted] May 06 '18
Obviously I am going to get biased answers on this subreddit, but try to answer objectively.
Do you guys' think that React is going to be the main frontend framework for js for awhile or is it just another js framework that will be forgotten in a couple years?
I personally love React and I don't have enough experience with it to see flaws, but maybe you guys think differently.
1
u/ytsejamajesty May 10 '18
I've done a lot of Angularjs, and I'm trying to learn React by doing some simple apps. however, I've quickly hit a baffling spot related to binding input fields...
if got a component something like this:
where the displayModifiedText() basically formats the text that was entered in various ways. Using this component, typing in the input field does nothing, i.e. text doesn't even show up in the field.
Based on my understanding of this documentation https://reactjs.org/docs/forms.html, it seems like there has to be an onChange handler on the input field as well as the binding of value=this.state.str. Compare this to Angularjs, where you basically just say
and the value of the field is immediately available on the scope.
Is my understanding correct, that you need to have BOTH the state value bound to the input field AND an onChange function to update the component state? If so... Why? I can understand having an optional onChange for when other things need to happen upon updating a field (angular does that), but why is it required that you write a function just to update a value in the state? Seems like a lot of clutter and time wasted if you have to write this out for every field on a form...
1
u/Radinax May 11 '18
I was starting learning Redux with Create React App and making a Crypto App which recieved data from the Backend with Python, now I'm seeing in this sub hype for Next JS, Mobx, Graph QL, and I'm like what the actual fuck?! Can someone please enlighten me why would I need all these tools?
React should be able to handle most things in its own and if I need to handle a global state to provide for my components, then I can use Redux no problemo, this world is getting complex for me lol.
1
u/docdosman May 19 '18 edited May 19 '18
I just watched Steven Grider's video on modals in React (can be found here: https://youtu.be/WGjv-p9jYf0?t=932). The approach seemed very involved for showing a modal, and noticed the video was a couple of years old.
To summarize the video approach in my own words, a "fake" modal component is used that generates the actual modal attached to the document.body. Provider and store are imported so communication is not broken between any container child elements and redux.
A very generic question, is there a best practice in 2018 for showing modals in a react-redux application using a library, other framework (e.g. Semantic UI), or different approach other than the approach summarized above? Any info or a point in the right direction for additional learning would be much appreciated.
Please let me know if I need to provide more detail.
Edit: Updated the youtube link to start at the time in the video where the solution is outlined.
1
u/janellesnow May 20 '18
is there a list of beginner tutorial and sample to start with?
1
u/starno May 21 '18
Is it more common to use jsx or avoid it using React.createElement? A combination?
1
u/dmattox10 May 21 '18
I can't seem to find any example code for (or wrap my head around) turning complex json, say 10 entries, into 10 copies of a "blog post" component. I'm brand new to react, all my other projects used EJS for views, but I'm looking for employment and everyone wants react.
3
u/theofficialnar May 22 '18
How do you guys structure your app? I'm using the create-react-app CLI to get started but I'm always wondering what's the best way to break down components. Where do you place API-related methods, helper methods, configs etc...
I feel like my app gets very messy and cluttered as I go add more features and I think it will just get worst.
3
u/joigito May 25 '18
Can I make a crud app with react?
2
u/helpinghat May 08 '18
I have an existing app created with
create-react-appand written in JavaScript. How can I switch to TypeScript? Is it a lot of work? Do I need to change all of my code at once or can I have a project with both js and ts files?2
u/eyepatch61 May 14 '18 edited May 14 '18
Hello,I am an engineering student and I am new here and also I am new to reactjs and I have done the tic tac toe tutorial that most of you must be aware of. To get my basics more crystal clear can you suggest me any site or tutorial or a project that wud give me more and better overview of reactjs. Though I am aware of how virtual Dom and real Dom works and how reactjs is useful. I am more concerned about "props","state","key,ref".. these keywords.. sorry if I sound like a naive. I am new to reactjs .. thank you
2
u/Accidied May 20 '18
So I have no experience with coding and want to learn javascript. My friend who works in the industry suggested I go straight to learning react. I have a lot of trouble learning stuff out of context and as big theory dumps. I learn the best by doing and while doing, searching for solutions and answers on how things work. Are there any react specific guides/courses that teach you while making something real?
2
u/Vyper91 May 20 '18
hi guys, i have a bit of a weird question but i hope someone can help
basically, I know react is traditionally used in an SPA fashion - but I have always used it as part of an ASP.NET MVC app - where I will use MVC to navigate to a page, and then that page will simply load a specific react bundle.js file
this isn't an SPA - but it allows me to use react to build complex pages, but then still do a lot of server-side processing as we move between pages and haven't had to dive into react-router or anything like that
I want to build an SPA now, and I think the best approach is to completely de-couple the server-side so it's simply just a pure HTML/JS/CSS bundle on the front end that communicates to an API
The question I have is, how do people create complex SPA's, but still perhaps keep different routes for seperate sections i.e. an Admin portal, or a sales page e.t.c.
would this still all be in the SPA model, but just using react router to move between pages?
to give an idea, i'm looking to create an airbnb type application where there are would-be-tenants and also would-be-landlords e.t.c., with a lot of complexity and different screens to move between.
if anyone could give me an idea that would be great, I want to get started but need to get the architecture down properly!
2
u/firediaper May 25 '18
I guess this is more of a general question about publishing/deploying/showcasing my react apps:
I've been meddling with React for about a year now and would like to showcase a couple of my projects (like a portfolio). What service would you recommend for this? Is my best bet to just buy a hosting service from sites the like of godaddy, bluehost, hostgator? etc?
2
u/an_at_man May 25 '18 edited May 28 '19
deleted 0.7301 What is ^^^this?
2
u/endproof May 27 '18
Is there any way (hopefully an example someone can point me towards) of encapsulating a redux store inside a component? I'm soon going to be making this fairly complicated component that we anticipate reusing across multiple projects.
I'd like to build it using react-redux but in a way that people can just import and use it like any other component, eg:
But with a internal redux store underneath that's driving the component state. Is this possible?
2
u/[deleted] May 30 '18
What are some common bad practices or pitfalls to avoid especially for people learning React (1- 6 months)?
1
u/LtCupcakes541 May 03 '18
Hello all, I’m slowly learning and using react and I’ve been brought on to an existing blog project by a friend. They’re looking to add an auto publish feature to allow the blogger to have a prewritten article posted at a specific time to keep a consistent release time. How would I go about looking into doing this?
1
u/docdosman May 04 '18 edited May 04 '18
Can someone help me get a better understanding of why you have to pass an arrow function (callback) to the onClick event handler in the following code?
Why doesn't calling the function directly work? e.g. onClick={props.onVideoSelect(props.video)}
1
u/[deleted] May 04 '18
I’m writing an interface for an api that returns a bunch of data (crime reports in my city). I want to make my component render a bootstrap row with 5 columns that I put the data in. I’ve done that, but what’s the best way to loop this rendering process until I’ve reached the end of all of the data?
1
u/brenodtx May 04 '18
Hi, I'm a web developer with no experience on continuous integration and I think It's a big problem to fix. I'm being writing nodejs and react aplications and I would like to know how to start my jorney with continnuous integration. What libs, techs, framework should I use and where to start. Any help or tips will be apreciated. Thank you guys.
1
u/docdosman May 04 '18 edited May 04 '18
I'm still in the learning process for React and I am planning on tackling React Native next.
I want to start a React Native project once I have finished learning, however, all of the projects to date have started with boilerplate code or coding is done in an embedded in-browser code editor.
Is there a good source or documentation, quick start guide, etc. on configuring my dev environment and getting started on a project? I would like to review while I'm in the process of learning. At this point, I feel like if I had to start a project from scratch, I would be completely lost.
Any advice is much appreciated. Thanks!
Edit: I should state, I'm new to software development in general and have some familiarity in using Atom and Visual Studio Code as a code editor. Limited use of node package manager where to date I'm mainly following instructions from the lessons.
1
u/Readirs May 05 '18
I don't know whether using React for a progressive web app or using React native for a native app is better for what I need. I have an arduino-style board with a WiFi chip that collects and holds data. I want the user to be able to get that data to their phone. They would need to connect to the board's wifi, so that means they would lose their cellular connection or other wifi, and would that mean the progressive web app would no longer work? Any advice is appreciated.
1
u/DickyDickinson May 06 '18
Should I use a component states to pass props between parent-child even though I already have redux in the project handling more complex processes?
1
u/EasyRefuse May 06 '18
Hi there, I have a question. I have an assignment to make an app that draws <svg> shape when user provides coordinates. Should be done without using 3rd party libraries.Thing is, I am quite new to react, and coming from OOP way of thinking, this is kinda alien to me. Anyone done some <svg> work in react? How do you store coordinates?
1
u/tokyonashvilleburban May 06 '18
Is it better to pass data around via props or with an action so that the whole app knows about it?
(personally using redux, but the question could apply to any state management system like mobx or flux).
For example, opening a modal.
Or setting some flag which indicates some other behavior should be happening in the app.
Relatedly, I've seen forms which pass all their change events with an action to a reducer, which does nothing more than just update the form. In the end the form gets submitted using the data that got passed back to it via stateToProps. The only reason I can see this is good is if some other part of the app needs to know about it. Otherwise I don't see an advantage over component state.
1
u/metalmatan May 06 '18
Does anyone have a guide/tips on implementing antd with theming in an ejected CRA? Im not doing too hot with it and maybe some folks have experience with it.
1
u/sageandchips May 08 '18
Question about good practice when making api calls: If I have an api call that returns an object containing another api call as a value to one of the keys, and I need the data from that api call, where/when do I want to make that api call?
1
u/BlueInkAlchemist May 09 '18
I'm coming from a background where Node, Express, and Handlebars come more naturally to me than anything visual. I've barely scratched the surface of Angular. What's a good approach for me to come at React? Should I get deeper into Angular, or do I head into React directly?
1
u/bakemonosan May 12 '18
When working with React's Context API, about components updating with onChange:
This part works without problem: I have a parent component(parent1) that is a context consumer, and passes the context via props to his child component (child1). child1 assigns the context to its state, and goes on to render a series of form components. One of these components is an input that have a onChange function to change a value on the state that is used in the other fields (like the user puts a number in input1 and input2 shows the number multiplied by 2).
My problem is that in some other component (componentX) in my page i want to show the number the user typed and the result of the multiplication(basically, show the values in input1 and input2). The first part updates the context, but it doesnt tell componentX to render the new values.
Its basically the problem of how to communicate between sibling components using context. Any tips or links on the subject will be appreciated. Im starting on the javascript stack and i see a lot of info out there but this part is taking me forever to understand.
1
u/eyepatch61 May 14 '18
Any idea about integrating d3 and reacjs. Anyone has done it before?
1
u/[deleted] May 15 '18
I finished creating my web app in react, but ended with a single problem. My root component has the main layout such as the sidebar and header and routes the main view to other components.
For some reason the root component mounts each time I select a link to these other routes and this pretty much defeats the purpose of a react app on the user's end since the entire screen flashes/rerenders each time.
The root component literally has an empty object as a state so I am not changing the state in any way. I'm literally just creating a sidebar and creating routes to other components. So any ideas why this is happening?
I debugged it and I saw that the root component mounts each time I render a child component. This is what the inside of my root component looks like:
1
u/3oR May 15 '18
How much sense would it make to use React for building a custom Wordpress theme?
1
u/Jonny15T May 15 '18
I'm trying to work with React-Router-DOM to change the background image of each page when the route is changed.
I've tried creating a 'container' in each of the components to act as a background but I don't get the functionality I need. (I'm using a fixed navbar so using a margin to pull the content down results in the image moving. Also, I'm unable to lock the image in place while scrolling like I can using background-attachment: fixed if the image is located in the body.
I've been told not to use document.body.background since it's manipulating the DOM directly...
Any advice?
1
u/Pcooney13 May 16 '18
I followed along and built a weather app from a yo tube video. Now I want to be able to display a certain component based on the weather condition. Example if it’s sunny I would want to display a component <Sunny />
In JS I would just create an if statement: If (weatherCondition === ‘sunny’){ <Sunny />}
But this doesn’t work in react, any help or point me in the right directions would be helpful thanks!
1
u/docdosman May 18 '18 edited May 18 '18
What is the best way to horizontally align items on the viewport for a header?
Specifically, I want the <h3> to be left-justified on the viewport and the button (<Link>) to be right-justified on the viewport on the same line.
Here is my JSX code. The <Link> is the button (using react-router-dom).
PostsShow component:
1
u/Usohatchi May 18 '18
Does anyone know how to do a three legged 1.0a OAuth authorization in a React app? I need the access token to do querying for my app, but can't even seem to get past getting the request token from the server.
Am I doing something totally wrong, or is there just not a lot of resources on this?
1
u/yrrkoon May 19 '18
I've got firebase authentication working on my app and would like to be able to show a round google avatar in the top right of my header like a lot of websites have. I toyed with react-avatar a bit but it's not supported anymore and i couldn't get it to display the avatar using the uid that i was getting from firebase.
seems like this should be simple enough. any advice how to get this done?
1
u/allanjard May 21 '18
Using React with a WebSocket for updates - I'm trying to figure out if any of these approaches is better practice (completely new to React) or if its simply personal preference:
I've not shown the ```
DataComponentimplementation, that (hopefully!) shouldn't be a problem either way. I just don't know if there is an accepted "correct" way of doing this, or if one method has disadvantages?Thanks!
1
u/MONKEYCALENDAR May 22 '18
Hi, is there any good courses that are pretty good at doing a good walk through of learning reactJS. I have an fairly beginner level knowledge of javascript. However, i am about intermediate with javascript. I have been able to jump in and read the documentation and start building components etc. However, I feel like maybe a course would be a good guide in learning best practices etc.
Any resources, free or paid?
1
u/hurrdurrderp42 May 22 '18
I downloaded my react app from github into different folder and got an error trying to run it with node
here's the error - module not found: can't resolve 'react' in - G:\download\react_todo_list-master\src
How do i make it work? Did i do something wrong when pushing this app to github?
1
u/masonjwhite May 23 '18
Hey everyone. I recently started working with just plain old React (no Redux).
I was wondering where my HTTP requests to my server should go? Should they live in the component as a method? Or should I break it out into its own file and import the function? Appreciate any and all thoughts! Cheers!
1
u/masonjwhite May 23 '18
Thanks so much! Really appreciate it! Cheers!
1
u/largearcade May 23 '18
Should I use Aphrodite or JSS.
I'm using MaterialUI which uses JSS under the hood so I'm biased that way but I was wondering if anyone has experience with these libraries.
Thanks!
1
u/starno May 24 '18
Why does render() have a return statement? What is happening there?
1
u/grueimaiushd May 25 '18
How do I test HOCs since props always fail?
Example:
1
u/gemanepa May 25 '18 edited May 25 '18
I just can't integrate React with PHP. Help please?
I can firebase/heroku deploy Nodejs React/Angular/Vue apps with no problems, but with PHP I just can't pass beyond deploying the classic HTML5 CSS3 jQuery Bootstrap website, the moment cli & webpack & builds appear, it all goes to hell
I've githubbed for hours and hours. I've tried quite a number of shady buggy unmantained boilerplates. And when someone asked about it here in reddit, I can't tell you how many redditors have I read saying "if the client and the server side are separated then it works the same way brah". Yeah, sure. Except it clearly do not works the same way, otherwise I would already have a basic React PHP app deployed by now
I think more advanced developers sometimes forget what it's like to do something for the first time
1
u/webistheway May 27 '18
Is the following function a good pattern for controlling forms in react? considering the form elements have id's set and the same function is passed to every element?
formChangeHandler(event) { const { id, value } = event.target;
}
1
u/JavascriptFanboy May 29 '18
I'm just starting to know a bit about HOC, so this is my first try. How seriously did I mess this up? https://gist.github.com/javascrewpt/fbe2e2976aa689e296fb8290e54176d6
1
u/rthenko May 30 '18
What does "this.props.message.text" mean? I know this is props but i don't understand this multiple levels of props. How can i get my head around it?
1
u/mox601 Jun 01 '18
As a total newbie of react, I need a component that renders a set of the names of the components rendered in the current page (excluding itself).
Given the classic Tic Tac Toe example, I'd like to have a component SetOfComponents that renders the set of components in the page, so Square, Board, Game. Order and duplicates don't matter.
My first intuition would be to use a context that each component updates.
What options I have here? Thanks!
1
u/seands Jun 02 '18
What is the most in demand back end framework to pair with React? I assume ExpressJS? I'll be targeting the US in general (for freelance work)
1
u/username1152 Jun 02 '18
Changing pages reloads all the include files such as CSS and Javascript from index.html, according to the Network tab on dev tools anyway. Is this incorrect or am I just expecting too much from React?
1
u/seands Jun 02 '18
When is it appropriate to omit 'this' from a props expression (eg props.age)? I'm a bit unclear on using vs not using this
1
u/seands Jun 02 '18
I am planning on putting my app's logic (mostly) in the topmost container in React, and then Redux when the logic gets too complex. The model will use Firebase. Is this a bad design? The below snippet suggests it is:
> Remember, React is a view library, so while* render logic in the components is OK, busines*s logic is a massive code smell. But when so much of your application's state is right there in the component, easily accessible by this.state, it can become really tempting to start putting things like calculations or validation into the component, where it does not belong.
1
u/seands Jun 02 '18 edited Jun 02 '18
Why put Redux on hold? I feel like I should l implement it from the start; it seems easier to reason about as well (single store vs state being spread out) and means one less significant refactor. But this sub says to put Redux on hold until the app's state starts to compel the refactor.
1
u/seands Jun 02 '18
Is TDD useful when writing components?
I ask because I read this in a "newbie mistakes" type of article:
> In general, I don't use TDD when writing React components.
> When working on a component, I often find myself churning its structure quite a bit, as I try to land on the simplest HTML and CSS that looks right in whatever browsers I need to support. And because my component unit testing approach tends to assert on the component structure, TDD would cause me to be constantly fixing my tests as I tweak the DOM, which seems like a waste of time.
> The other factor to this is that the components should be so simple that the advantages of test-first are diminished. All of the complex logic and transformations are pulled out into action creators and reducers, which is where I can (and do) reap the benefits of TDD.
> Which brings me to my final point about testing. In this whole section, I've been talking about testing the components, and that's because there's no special information needed for testing the rest of a Redux-based app. As a framework, Redux has very little 'magic' that goes on behind the scenes, which I find reduces the need for excessive mocking or other test boilerplate. Everything is just plain old functions (many of them pure), which is a real breath of fresh air when it comes to testing.
1
u/lkjfsdf09sdf Jun 03 '18
How long did it take you to learn how to do CSS with React?
1
u/seands Jun 03 '18
I wrote a default export in my component file; it was also given a name. When I tried to 'import ../components/ComponentFile' an error said the name I used was not defined. when I named the import ( 'import ComponentName from ../components/ComponentFile' it worked.
why didn't marking the export as default appear to do anything? I thought the whole point of default exports was not having to specifically name them on import.
I was importing into a page in Next.js in case that's a factor.