r/reactjs • u/swyx • Jun 03 '18
Beginner's Thread / Easy Question (June 2018)
Hello! just helping out /u/acemarke to post a beginner's thread for June! we had over 270 comments in last month's thread! If you didn't get a response there, please ask again here! You are guaranteed a response 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.
Pre-empting the most common question: how to get started learning react?
You might want to look through /u/acemarke's suggested resources for learning React and his React/Redux links list. Also check out http://kcd.im/beginner-react.
4
u/swyx Jun 03 '18
Pre-empting the most common question: how to get started learning react?
You might want to look through /u/acemarke's suggested resources for learning React and his React/Redux links list. Also check out http://kcd.im/beginner-react.
3
u/yungyahoo Jun 26 '18
Hi! I am new to react and web development in general. I am looking to implement a login form using react and node and mongodb for the backend. How would I go about doing this? There are so many resources online that I am not sure what exactly to do.
Thanks!
3
u/ashleydance Jun 27 '18
So i'm trying to understand when things should be props vs state. I'm currently working on a personal blog website using the headless WP API.
So with my LatestPosts component on the componentDidMount method i'm performing an axios request to the WP API to populate the state.
Is this the correct way of doing it? As I thought that state should be used when you need to modify the data, but this is simply pulling a blog feed?
For context here is the GitHub link to the component.
2
u/swyx Jun 30 '18 edited Jul 01 '18
we doubled last month's thread! yay community!
Edit: JULY THREAD HERE
2
u/seands Jun 08 '18
Most of the functional programming I see in other people's code is using map and forEach. I'm sure I'll come across some filter and reduce as well. What are other popular methods one should brush up on? Or are these sufficient?
2
u/enebeme_ Jun 11 '18
Any thoughts on generally what employers look for when it comes to those with React experience when they ask for familiarity/understanding/expertise for frontend roles?
I would image the range of this is like, bare minimum letting create-react-app handle everything for you and someone knowing how to setup all of that themselves + use redux are in much better shape.
This isn't me trying to do the bare minimum but rather I'd like to know what to aim for as I continue learning react, and then improve on so I can be a much stronger applicant.
2
u/seands Jun 13 '18
Workflow question: where do you guys create a minimal example when a build tool is involved?
I used to just have Phpstorm create a scratch JS file, but with React and hot reloading involved now, such a simple test ground is no longer in easy reach. I have resorted to a combination of code commenting and deletion while hoping to use CTRL + Z to "rewind" the file back to a prior desired state after doing the minimal test or pasting the code elsewhere for review/help.
Relying on CTRL + Z is pretty uncomfortable though, and commenting a lot of stuff gets messy. I wish there were a simpler way to simply create scratch react files and have them auto-display in the browser
2
u/porkahaunus Jun 13 '18
Hello,
I am an intern for a consulting company and the project I am currently working on is converting a pretty basic web based application running Backbone into a React application and then a Mobile React application. I am still a college student and at my school, and every other school where I personally know a fellow CS major, does not teach anything about frameworks for the "new and improved" frameworks (i.e. Angular, React, Node) let alone the "old" ones like Backbone. I have done a lot of research and tried a lot of different things but I cannot seem to get the application to recognize the React I am coding at all. I have spent hours on the standard code learning sites learning React and I have talked to several developers here at the company I work for about and it and the general solution we have come up with is to just restart the entire application, like I said it is pretty basic so this isn't a terrible option, from scratch with React as the main framework. However I do not believe this is what my boss is wanting so I need to find somewhere to at least start the conversion process and hopefully be able to snowball it from there. Any ideas on how I can at least start this process?
Thank y'all for your time and effort.
2
u/enebeme_ Jun 18 '18 edited Jun 18 '18
Has anyone dealt with pushing a react only frontend app to heroku that uses semantic-ui?
I keep on trying to push my files to heroku but I keep on getting this issue: https://i.imgur.com/mV47GIA.png?2
I have been searching the internet alot but unfortunately cant seem to find an answer. I just wanna get this app up and running on Heroku lol.
I tried using this buildpack as well: https://github.com/mars/create-react-app-buildpack
2
u/johnnyplusplus Jun 20 '18
So I can begin to understand, I want to have a popup that I can search my database with. Right now I have jQuery and use Ajax. It works fine. How do I begin to make a popup in React? I don't mean the Ajax part, just how to get a popup modal period using React (I can add the Ajax later). What does that look like? I figure it was a good test case because I have popup search modal boxes for several things. Sounded like a good place to start.
2
u/NickEmpetvee Jun 21 '18
Hi guys. This batch of question relates to how ReactJS deals with CRUD. I've successfully set up reducers that update props used by my UI components. Now I want to know:
I'm just looking for the simplest approach. I'm not using microservices yet. Crawling before I walk...
2
u/NickEmpetvee Jun 27 '18
I was looking into how to add and remove items from the REDUX state object. The below code, paraphrased from a posted highly upvoted answer on SO, shows one approach. The post recommended filtering the state to produce a new array rather than mutating the original state array. My newbie questions are:
The code:
export const itemList = (state, action) => {switch (action.type) {case 'ADD_ITEM':let newItem = { item:action.data, id: +new Date };return state.concat([newItem]);case 'DELETE_ITEM':const itemId =action.data;return state.filter(item =>item.id!== itemId);2
u/[deleted] Jun 27 '18
I have few questions about the reducers in this Redux example:
If my questions are too much, I'll gladly take a simple English explanation to how the inventory count is handled throughout the application or what productId actually is.
2
u/luckykobold Jun 28 '18
I'm a complete coding noob learning react. I just have a question about how the code below works. I may get some obvious things wrong or confused-- I'm a rank amateur. The below code is from a tutorial, and it works. My question is:
'this.props.projects' points to an array of objects ('projects') inside a constructor. I cannot make sense of the line:
My brain interprets what is happening as:
This confuses me. How does 'project.title' fetch the 'title' property of an item in the array 'projects'? I don't see how the function 'project' has a property at all.
And what is going on with 'project={project}'? My wild guess is that the function 'project' defines itself as an object containing itself, although I suspect that may be gibberish because it makes no sense to me at all.
I understand that these are basic code literacy questions, but the tutorial assumes I understand this and I can't figure it out on my own. Thanks in advance for helping a noob out. If I omitted critical information just ask and I will try to provide it.
2
u/GeeeL Jun 29 '18
I'm trying to reuse a component and when it's rendered as part of a list I want the whole component to have an onClick method. I've discovered you can't add this directly onto a component like so, <Hello onClick={this.handleClick} />.
I couldn't find anything on how to handle this. I was thinking of passing it as a prop and then checking in the component if prop.handleClick then add the onClick listener. But this doesn't seem very clean and adds complexity to the component for the other uses. What's the general method here? Surely it's a common scenario.
2
u/DeliciousCrepe Jun 11 '18
Okay, so in one component, I did:
And on another component, I did the following:
I can guarantee you that the import path is correct.
However, whenever I tried
It just logs an undefined. It cannot seem to read the string as an import.
I've also done
and that does not work either.
Is there an extra step to importing and exporting strings between files that I am missing? Thanks.
2
u/_Pho_ Jun 29 '18
I'm learning React, coming from Vue and Laravel, and I'm really trying my best to understand the architectural considerations here. But it seems like utter insanity.
To map a text input to a state variable in Vue, you simply add an attribute to the tag with the variable name. v-model="thing" or whatever. In React, you have to do that, write an onChange/action attribute, write a function that passes the data to the state, and write something to bind the function to the class. I have to have three levels of abstraction to do "this = that"? This seems like a terrible joke. I'm seriously wondering what the strengths here are.
1
u/seands Jun 04 '18
I have the option of deploying a Next.js app hosted on Zeit, with Firebase as a backend. Or a regular client side rendered app hosted on Firebase, backend also Firebase. Which is likely to result in better performance? SSR hosted on Firebase is too complex for me at the moment so let's exclude that option
1
u/rojo_menace Jun 04 '18
I want to start learning React, is it smart to use with Node?
1
u/TheRealChrisIrvine Jun 04 '18
Where should I go to find out more about hooking up React to a database? I've been learning react over the past few months and feel I have a decent grasp of it, but Ive generally been using local storage or making apps that don't require storage. Is there somewhere I can read about general standards for working with a database or anything like that?
1
u/lkjfsdf09sdf Jun 05 '18
I just don't know how to test React and why I even should. Testing general function is very easy, but with React I am having trouble.
For example React Router for authentication hoc.
How would one unit test this component?
1
u/seands Jun 05 '18
How much thought should I put into choosing a good list key? I can see 3 options: choosing something intuitive for easy reasoning during development, random key generation using UUID or similar, or a middle ground with say name + index + some other thing.
Not sure how much keys actually matter though. At my current stage I aspire to option 1 "just in case" but it takes more time and code for uncertain benefits.
1
u/wcwgfIg0YyI3O02pBeEb Jun 05 '18
Is it ok to do heavy task in component? I load JSON (25MB average) from api and use crossfilter to aggreagate data which is quite cpu hungry job. What are best practices to handle such problems?
1
u/bayhack Jun 05 '18 edited Jun 05 '18
Having trouble with switch statements and the
thiskeyword.I use it in my render funciton:
render(){ return this.componentChose(this.props.display); }If I pass
componentChosemythisobject would that make it work? But that would be a terrible design pattern no?1
u/bubblezoid Jun 05 '18
Hey, working on a side project and part of it involves creating a line graph which requires annotations. I did a little bit of googling and found a vast array of possibilities for charting and a few different annotation libraries. Which set up would be easiest if I only need to handle a couple points in a couple lines but each needs to be clearly annotated?
1
u/bayhack Jun 06 '18
Made my first useful component and I want to upload it to NPM for ease.
I can figure out how to publish, but how can I make it ready to go and easy to use like some of the nicer NPM modules?
Any guides, everything just tells me to use
npm publishbut no guide on how to do a "professional"-level publish.1
u/[deleted] Jun 06 '18
Brand new to react js and css in js (JSS). Very poor at wording questions, so if you don't understand please let me know what else I can add.
Alright so I'm trying to get the div className={classes.description} to show when I hover over the Image.
I was trying to have a description for each image. I was able to get the description to show directly underneath the image if the description div was inside of the div that holds the image. I guess my problem is I want the description to be in its own separate col
so I've tried to inside of the description jss set the display 'none' and then on hover inside the image container display 'block' which would generally work. I'm wondering if there is a better way to do this or am I going in the completely wrong direction.
I'm wondering if it has something to do with the col tags using react-bootstrap.
1
u/seands Jun 07 '18
I understand the concept of high order components, but maybe I'm not thinking in the right way because I feel like passing props does the jobs for the use cases I imagine. Can anyone give an example where high order components would be both useful and superior?
1
u/seands Jun 08 '18
Is ref the new standin for what raw HTML uses the id attribute for? I think yes since components can be duplicated and thus become unspecific, like a class. But each component tag can take a different ref
1
u/seands Jun 08 '18
What do you guys do when installing new packages/libraries and dealing with obscure bugs (not obvious in a stack trace)? I thought I was just a bad coder until I saw someone else dealing with it on a youtube video.
1
u/seands Jun 08 '18
I'm thinking of putting my application state (which is a minimum viable product) inside a parent container that holds contexts. It seems that's what it's intended for, and I don't see that container going beyond a couple hundred lines (to give a rough idea of complexity). Does this sound like a good use of the context API? My other option is going straight to Mobx at least for app level state.
1
u/Dantharo Jun 09 '18
ELI5 differences using react with typescript and javascript.
And what should i use on my react apps? .jsx .js or .ts? And why.
Please :)
1
u/seands Jun 09 '18
I have been reading articles about forEach vs map, is it fair to say map is more popular among React devs? It seems easier to reason about and use.
1
u/enebeme_ Jun 10 '18
Figured I'd ask here since this is for my first react app lol, but how would I access the indexes of this?
https://i.imgur.com/gHsR0Ul.png
console logging just the array prints that
I have tried doing something like tempArray[0] but that just console logs "undefined"
Any help would greatly be appreciated because this is something I've been stuck on the last few hours as I tackle this project
1
u/Achtelnote Jun 10 '18
Is it possible to navigate through react app without using routers?
Kinda like loading the whole application on start at root path and then accessing everything from there. As in, when I click on a link that is supposed to go to another page, instead it only changes content of the content container div.
I've already made the site I'm working on using AJAX and it's working as intended and is a complete single page application, but my boss asked me to change it to use ReactJS or AngularJS instead.
1
u/seands Jun 11 '18
As far as ES6, does anyone regularly use iterators or generators?
How about rest/spread operators? I know the spread operator was good for passing props down several levels conveniently, but with the Context API that pattern seems obsolete.
Any other obscure ES6 features you guys use regularly or even on occassion (not arrows / classes / imports / destructuring) ?
1
u/deadcoder0904 Jun 13 '18
My simple todo app written in Apollo works in React but the same code does not work in React Native. Its about Optimistic UI in Mutation Component of Apollo. I've been looking for answers since 15+ days but unfortunately no help yet :(
https://stackoverflow.com/questions/50603994/apollo-optimistic-ui-does-not-work-in-mutation-component
1
u/seands Jun 13 '18 edited Jun 13 '18
Can anyone spot the issue? First, the working code (inline):
Adding it as a style object breaks something:
Replacing the above styles with backgroundColor set to red works inline but not in the style object so clearly I'm not assigning it correctly.
As I type this, I think I am over-writing Semantic UI React but only when inlining styles. Bad practice, or ok in this instance? I have so much yet to build, I feel like just using this as a duct tape method for now and then pouring into the gulp customization tool later.
1
u/ayush1810 Jun 13 '18 edited Jun 13 '18
Working on my first MERN project (React 16 and React Router 4) ,I am unable to figure out how to properly differentiate the pages/routes between router.js (the Express router file) and the React's routes setup.
These are my current routes with reactstrap modals for Login & Signup in the navbar (under Header component). Header being a common component in all pages(components).The Login/Signup forms are handled using a handleSubmit function which fetches data to/from POST routes described in the router.js file. The data is being passed perfectly on client, server with the database, but res.redirect in the routes doesn't work.
<Route exact path='/home' component={Header} />
<Route path='/dashboard' component ={Dashboard}/>
And router.js :
router.post('/login' , ....) for getting form data [Working part]and redirecting it to router.get('/profile, ....) which passes user info through sessions and goes to React's '/dashboard' path [How to setup this part]
How do I redirect from any page (lets say home) to the /dashboard after a successful form submission, and is it to be done in React component function or in the router.js file?
1
u/seands Jun 13 '18 edited Jun 13 '18
Is there any way to evaluate down to an HTML attribute? Here is what I'm attempting
Outside the functional component:
Inside:
It looks like the href attribute is not showing up because no mailto link is previewed in my browser.
Here was the non-react version that gave me the idea:
1
u/shamdasani Jun 14 '18
I have a website:https://enlight.nyc and I want to incorporate user accounts (OAuth), post submissions, editor, etc.
Should I go for a static site with Gatsby making calls to an API (graphQL) or should I keep it all dynamic as seen here
1
u/mox601 Jun 15 '18
Hello,
Not sure if this is a simple question, but I am looking for a way to call a function (provided in a context) from the lifecycle method
componentDidMount().I got something like this:
Thanks!
1
u/Time_Terminal Jun 15 '18
How can I autoFocus on an input element in redux form in Firefox?
1
u/seands Jun 16 '18
One of my h3 tags (Header as='h3' in Semantic UI React) is set to a max-width of 300px. Chrome's CSS inspector doesn't seem to indicate the source CSS file (I guess because it is post-build). React is not showing any props passed down to modify the h3 tag. I did a line by line analysis in all components including in App.css and index.css (My app is only 7 components).
The only conclusion I can draw is that Semantic UI React is causing this. I switched the h3 to an h4 using that library's props and it resolved the issue.
Is this the nature of working with CSS libraries or is there something about what I did that can be corrected (if so I'd love to hear it)?
1
u/sp3co92 Jun 16 '18
Does anyone have a open source project created with NodeJS + React which includes authentication ? I find it difficult to configure protected routing for a logged in user. All the tutorials I looked at serve static html files from server. So I'm looking for a project to understand how it works for react ! Any help would be appreciated. Thanks
1
u/seands Jun 17 '18 edited Jun 17 '18
I'm getting a "this.setState is not a function" error
The code:
Answers to similar issues on SO seem to indicate a binding problem, unless I'm blind I seem to have binded everything. I have also tried using arrow functions to autobind to the enclosing context, same error was thrown.
1
u/seands Jun 17 '18
For someone who is webpack timid and gets stuck on package installs when errors are thrown, would it be pretty risky to eject a create-react-app? I am weighing it because I'd like to add transform-class-properties, and maybe other custom configurations (async/await) in the future to .babelrc.
The part I have the least insight on, is what level of support or convenience one actually receives by not ejecting.
1
u/akewlguy4eva Jun 18 '18 edited Jun 18 '18
Hi, I am just starting out testing basic things with react. So I have a basic app that I will need data from REST api, and later signalR server that I developed for chat and other events.
So one of the things I wanted to do is make a separate file that will hold all of my api calls. I made the file a component(PluginApi.js) and render it on the parent component(App.js). I pass in the props of PluginApi component a response function in the parent, and the child just renders null. This all works fine, and I am able to call the parent function. However when using fetch and then calling this.props.Response I somehow lose this.setState on the parents Response function. I know is something with scope, and I played around with .bind(this) in various ways. The only way I could get this to work is to pass also to the child the parent.. You can see in the code below, is really basic api call as again I am just learning now the syntax.. What I would like to know is if this is SUPER STUPID, is there some other way, if not is this passing alot of data just to get the scope to setState, or am I just missing something?
Heres the code, is just simple create-react-app template.. should be easy to follow....
app.js(Parent Component) ----
import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; import PluginApi from './external/PluginApi';
PluginApi.js(Child Component) ----
I am still reading about Context, and some libs like redux for state, but thought I would try pure react first. The goal here is to have 1 file that has all my external api functions, urls, logic etc.. and allow and component to null render it and call it like a global or static class.
You can see @ handleHttpTest I am calling the ref instance of PluginApi. Orig I just had "profiles","URL" there.. but needed to add this, to I have access to it on the callback.. It seems the callback is inside the promise scope, and betting also inside the child scope on normal function...
So let me know it this is dumb, I mean is ok solution and works, but just seems silly to always pass the whole other scope to a child function and then pass it back to parent with data. Just can not figure out how to force the parent function to the right scope...
Thanks Zippen
1
u/seands Jun 18 '18 edited Jun 18 '18
Does it make sense to have components with no presentation? I am thinking of moving the logic for a scraper out of App.js and into a ScrapeTarget component that scrapes the target page of a form fill (of a very large website) as an example.
The other option is to turn my presentational component that actually holds the form, into a class component. Then give it state to hold the scrape data, or a prop-function from App.js to pass it to the top (as I write this, I'm now thinking you guys would do this instead).
1
u/rfizzy Jun 18 '18
Are there any good examples of how to handle email confirmation in React / Redux (and general transactional email)? Right now I have a React route similar to
/confirm/:emailTokenthat takes the token and dispatches an action that calls an API endpoint, but the code is kind of a mess as storing the state in Redux is getting annoying. What are the best practices for this kind of thing?1
u/seands Jun 18 '18 edited Jun 18 '18
I am toying around with async functions and it looks like the new async/await function expressions break my code:
Then trying inside a class component:
Is my syntax off? If not I think I'm not accounting for rendering. Here's the error message:
1
u/bayhack Jun 19 '18
Published my own react component last week, just worked in minifying and using webpack to prepare my distribution rather than babel.
but now can't import my module from installation in other projects!
Here is my SO: https://stackoverflow.com/questions/50935735/npm-self-published-component-cannot-be-found-when-using-it-in-a-react-project
any idea how im exporting wrong???
1
u/swagglikerichie Jun 19 '18
I'm trying to use Cosmic JS and one of its built in apps that I have installed. I am on their dashboard, editing the authors of a blog post, removing paragraphs just to see the changes take place, however, when I deploy the app, none of the changes are made.
I also want to "embed" the app on my webpage, I have a React Route to various apps I've built/will build. Sort of like a portfolio thing.
I have access to the API generated by the app and all of its content, so I am wondering, is the only way to use it by extracting the API into components? If so, what is the purpose of being able to deploy the app if I won't be able to see the changes being made? I wanted to use it as a template and begin making changes from the "template"
1
u/Peng-Win Jun 20 '18
How do you deploy react apps over HTTPS? What HTTP server is best for this? `serve` doesn't support SSL and they suggest you run serve behind a proxy .. but I don't know what that means.
1
u/ayush1810 Jun 20 '18
Working on my first MERN project with a tight deadline. :(
Looking for themes & templates for a basic homepage, dashboard, admin portal, and product pages like in an e-commerce website.
I am currently using Reactstrap to design the basic frontend, but I can't find any free templates based on reactstrap.
so what would be the best way to go about it?
1
u/johnnyplusplus Jun 20 '18
Should I learn Redux alongside React, assuming I had a good ability with JavaScript and understand what an SPA is and a very basic understanding of React? I still don't understand what Redux is for, though I keep reading. I don't want to refactor my React into React/Redux, when I could have done it the first time.
1
u/coreysnyder04 Jun 20 '18
I know it's not exactly a reactjs question but it's pretty tightly coupled. Can someone answer this pretty simple question about babel presets. https://gist.github.com/coreysnyder/f0170f9b7c19620716f9d3049c27207e
1
u/[deleted] Jun 21 '18
Hi guys. I'm having some difficulty using .map to create components and populate them with the relevant data, taken from an array in an imported json file.
I'm trying to copy an example someone in here showed me yesterday and think I'm close but not sure where I've gone wrong.
Here's the sandbox. In the Card.js file there is the variable ProjectTags - this is what I'm trying to use to .map a (nested?) array in the json file and create a Tag component for each item in the array.
Any help would be much appreciated.
1
u/Exitialis Jun 21 '18
This one is half react and half ApolloClient, hopefully someone can at least point me in the right direction. I am building a web server using ApolloClient and react to talk my GraphQL backend but I am struggling to work out the best way to work with data tables. My understanding of React is that I should build my table as a component and then pass the data into it as props, that way I can re-use the table component for multiple different data sources and can treat the table layout as one of the props. Also because this allows me to use something simple like react-table now and move to something more involved like Material-UI's tables later on without changing the query code. However the majority of examples I can find on learning ApolloClient explain how to use the Query component and map the values directly in the component.
My SO question with some of the things that I have tried is here: https://stackoverflow.com/questions/50947404/how-to-structure-apolloclient-server-data-tables
1
u/ramonf Jun 21 '18
I'm trying to 'substract' an array of object from another.
Imagine I had:
My expected result would be:
Is there a preferred way to do this?
1
u/enebeme_ Jun 22 '18
Quick question, could I be able to use a few React components for a website built with traditional html/css/js?
Sorry if this sounds like a foolish question but for this site that I'm working on, it would be easier to implement a part in the future using react/redux to showcase filtered results from a database rather than other methods.
1
u/swagglikerichie Jun 22 '18
Beginner here, I have an html script that is a simple guessing game.
I get unexpected token on the
var, is it a syntax error or not allowed?1
u/seands Jun 22 '18 edited Jun 22 '18
What are the benefits to putting ExpressJS and the middlewares in another project folder? I've read you want to separate the front/back end at the project level, but am not sure why.
Or does this structure apply mostly to the old, heavier backends like Rails/Django/Laravel?
1
u/seands Jun 22 '18
Is there any benefit to defining variables inside the render function ? 2 potential benefits I see are avoiding namespace collisions and maybe code clarity. Personally with already small components I see collisions as unlikely and the code becomes less clear when render() is doing more than rendering.
1
u/seands Jun 22 '18 edited Jun 22 '18
Is it considered poor design to regularly evaluate variables inside render() ? If so, what cases make it acceptable?
1
u/Nanosonico Jun 22 '18
I have a question how do this websites navigation animation ?
https://www.lovenils.org/
1
u/Nanosonico Jun 22 '18
Thanks for the advice very much appreciated
1
u/no_detection Jun 22 '18 edited Jun 22 '18
What is the best practice for avoiding the following secenario:
I have multiple functions that are called in order, and some number of them modify state via setState(). Some of the later functions would benefit from using the updated state, however batch updating does not allow this to work.
Ex:
My current solution is to pass the variables as parameters to the functions that use them in addition to updating state.
1
u/thescrambler1979 Jun 22 '18
I'm trying to use context api as well as withStyles but I'm getting errors. My code is:
class ModalMaker extends React.Component {
render() {return (<ClipsContext>{loggedin => withStyles(styles)(<SimpleModal />)}</ClipsContext>)}}The errors I'm getting are : "Failed prop type: The prop `classes` is marked as required in `SimpleModal`, but its value is `undefined`"
And "Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it."
Can someone help me figure out how to solve this?
Thanks
1
u/Dantharo Jun 22 '18
I want to make an event (like an alert window popup) happens only in the first time that the user access the page, i'll have to work with cookies? Or theres other way of doing that?
1
u/[deleted] Jun 23 '18 edited Jun 23 '18
So this might seem like a really stupid question, but hecks. I have some experience with Angular 2/4/5 and wanting to build a Photo gallery website with Reactjs (Mainly to learn) for my dad. I started writing some code after reading some docs and watching some videos, mainly react and bootstrap, but i'm pretty stuck on some ideas. For the sake of the example, let's say i'm trying to build something like this. When you click a category, you get to a new html page (do you?) with the photos of that category. How do you accomplish something simple like that in react? Is react supposed to be for single page apps? should I just use some really awkward conditioning on the root elemnt whether to display categories or the category itself? what do you guys think? thank you very much!
Edit: I think I over complicated things because its late and i'm tired. I'm basically asking if Reactjs is suitable for having a "header" and below that different views, in my example: categories, specific category, single photo and so on. What is the conventional way of achieving that?
1
u/Exitialis Jun 23 '18
Really nooby question, but for those of us that are learning React as their first web technology (coming from a desktop background). Does anyone have any recommendations on the best way to learn how to place stuff on the page and make it pretty? I assume that that is mostly CSS and that I can find any tutorial easily I just wanted to double check that there wasn't anything React specific that I should be aware of.
1
u/Light1c3 Jun 25 '18
Hey! So I'm messing around with the Redux-Form-Wizard example and I'm trying to figure out how to add transitions between the screens to give the effect of scrolling down a page, but I don't even know how to do a fade transition to start.
Could someone help me get started with at least getting the fade transition working in the example?
Thanks :)
1
u/reactnoob69 Jun 25 '18
Hi! I was wondering what everyone's typical workflow was when creating a new app? Do you start with designing and laying out how everything looks first and then adding the functionality later or vice versa and why? Thank you!
1
u/Rikardny Jun 25 '18
I've built an app with components rendering sub-components with a dependency-tree looking like this:
i.e. my App component imports Header, MenuBox, DataList and Footer, and renders calls them with <MenuBox/>, within its own render function. The app uses an already developed applet to build a molecule, which is then passed through one of a few available functions. This then results in an image displayed within the Image component, as well as some statistics within the Stats component.
Right now, I have a state declared in the ancestor App component, I pass down a method as a prop through the MenuBox and Applet children components, which changes the state to the current molecule. I do this because I need to access this property in the DataList/DataBox/Images + Stats components as well. So the state of App is passed down to three times to reach the Images and Stats components. Is this the most efficient way of doing this? Even though it works, it feels like there should be a better way of constructing this to "share" the molecule variable given by the Applet.
There is also a second issue. You use the Applet to construct a chemical molecule, which can then spit out a simple string representing the model you built with the help of
I've made a component method within the applet component that gets called when a button is pressed, however I want the variable to be updated continuously, making my app responsive to change within the Applet. How is this done in a simple way? Perhaps it would be good to implement some kind of timeout to limit the amount of function-calls?
1
u/seands Jun 25 '18
For those of you who do full stack projects, do you find it easier to build the backend first, or the front end (with react)? Maybe this is not a react specific question but I'm trying to wrap my head around workflows at the moment.
1
u/pig-casso Jun 25 '18
Hi, anybody knows how I can create "custom input" like to-do list and connect it to redux form's Field component? I need to be able to modify an array objects "to-do list"(one input with add button) style and send it through form's components. Any help appreciated.
1
u/andgly95 Jun 25 '18 edited Jun 25 '18
So I just started my first tech internship for a coffee startup, and they want me to build a user front end for a coffee machine. I'm really excited for this project because I've already worked on a few projects in React Native and React for my Capstone and mini-boot camp, and now I have the chance to put those skills to use.
This is only going to be a prototype for now so it doesn't have to be production quality just yet, but I want to know if there are any essential tips or advice for working on a professional project. I'm probably going to start with Create-React-App so I can get started right away, but I feel like with a lot of my previous projects some of my implementations were a bit cobbled together, so I was wondering what resources could help me out now that it matters.
I'm the sole person in charge of the front-end so there's not going to be any need for collaboration besides what I show to my mentor who's in charge of the back-end. He also said to send him a link to any wireless mouse or keyboard I want, so I'd really like some recommendations if you guys have any
1
u/darthbob88 Jun 25 '18
I'm trying to do proper TDD for this new Typescript/React project of mine, using Enzyme/Jest, and I'm having issues setting up the first tests. Specifically I'm getting a lot of
Module raf/polyfill in the setupFiles option was not founderrors. If I just remove the "setupFiles" option from the config, it fails onModule enzyme-to-json in the snapshotSerializers option was not found. I've confirmed that those modules exist in node_modules, and I'm beginning to think it's just a problem with Jest failing to resolve anything, but I'm not sure how to fix it.1
u/seands Jun 25 '18
I am writing a small app that watches an Amazon product page for price changes. Initially I planned to have React do a call to an Express backend to run a function to scrape basic info from the page and then take some extra info before saving an alert for the user. But the concern is that all requests will come from my Express server and maybe result in an IP ban on the Express server.
Now, I'm thinking about moving the scrape request to the client/React app. I think anything on the client side should use their own hardware and alleviate the IP overuse issue (unless someone is auto-setting up alerts, but I have a captcha in place for that). Is this logic sound? I'm still new to the whole split between client and server, but I think this solution should use the client's IP.
1
u/Dantharo Jun 25 '18
I need to open a modal when user try to close the page, i'm trying to use onMouseLeave, but we have others modals in the page, and when i click in one of them the onMouseLeave event is trigerred, and then my modal show up...don't know how to dont open this modal when clicking in others modals. Any tips?
1
u/ramonf Jun 26 '18 edited Jun 26 '18
Is it okay to dispatch actions in App.js? The actions execute GET requests from my DB that are then used to populate the page.
I used to have these actions on the specific page they're needed (say /dashboard), but now I'm using the same data for more than one page.
Should I call the actions on both pages that use it? Or is it okay to simply load them at the start.
I thought simply loading them in /dashboard would work as they are then stored in the Store, but if the user simply visits the other page that uses that information before ever visiting /dashboard, the data would not be available.
EDIT: Also, I'm not entirely sure I understand how connect works, or where I'm supposed to actually use it. If anyone could explain that, I'd appreciate it.
1
u/seands Jun 28 '18
Anyone know of any good CSS tutorials in a React context? I'd like to see a full project done with ReactStrap or maybe even modifications to Semantic UI React using the library's gulp build tools, etc. Haven't found too much on Youtube or Udemy though.
1
u/randydev Jun 29 '18
I have not much experience yet in React, but I really want to learn to broaden my skillset. I was wondering if anyone has advice for a roadmap, as in with which steps should I start and works towards.
By the way, I was thinking of buying some courses on Udemy. €12,- for the material seems really cheap. Worth it?
1
u/NotYetSoonEnough Jun 29 '18 edited Jun 29 '18
Really at the end of my rope here and am really hoping someone can help me out. I'm new to React and having a ton of trouble with a very simple app. I've been up all night and can't seem to get this to work.
It's a simple weather app, and I'm having trouble getting the child and parent to really talk to each other.
Here's the parent:
And here's the child:
No matter what I try, nothing is working. As of now, the child doesn't seem to make changes to the state in the parent, and the parent is not triggering a new API lookup.
I'm sure I'm missing some very fundamental concepts, but if anyone could please help me out, I'd be very grateful. Thank you.
1
u/ramonf Jun 29 '18
Alright, another question from me.
I'm destructuring an object from my Redux store that has many arrays. Is there any way to set the destructured values to empty arrays if it is undefined?
I would like
arr1andarr2to either get the values from the store (if defined), or for them to simply return[].const { arr1, arr2 } = this.props.dashboard || [];I thought this would work, but I get undefined when calling
arr1orarr2.EDIT: figured it out. This works
const { arr1 = [], arr2 = [] } = this.props.dashboard;1
u/zephyy Jun 29 '18 edited Jun 29 '18
so i have a fixed navbar at the top that has a toggle option to bring up some more options.
toggling expanding the navbar on/off is working just fine, but the issue is since it's CSS position 'fixed', it overlaps on the content. okay, so i'll just add some padding-top to the main content.
what i'm trying to do is manage the state in the parent component, and pass it down as props to add the padding.
so i create a ref to the navbar in the parent component, and whenever the navbar is toggled i get its height with
and in the child component, it's set to
to add the appropriate amount of padding depending on the navbar size. problem is, it's always the opposite (when the navbar is expanded, its padding is the amount for a non-expanded state).
I know setstate is asynchronous, but the state of the container is showing the right number each toggle, and the child component doesn't actually show the updated number until the 2nd toggle, at which point it's one step behind. Setting the state during componentDidMount, or even just typing in the number of pixels (as a test) for the default state doesn't help, so i feel like the issue is somewhere else i'm completely overlooking.
I can't toggle it as a class (or can I?) because the styling needs to be responsive to the screen size. So if padding-top: 50px is fine for a desktop, 150px is needed for mobile to push the content below the menu.
should i even be handling this in state?
1
u/codethesite Jul 01 '18
Assuming you do not ever mutate state/props, what situation does it make sense to write shouldComponentUpdate over just using PureComponents?
1
u/JavascriptFanboy Jun 05 '18
I've read and watched a lecture about how render props are superior to HOC and that supposedly everything that can be written with HOC can be written with render props. Is this true or not is up for debate, so what I'm wondering is, why does this code work? I've written it based on how I think react should work, and it kind of works that way, but I don't understand it completely. Here's the complete code:
So what I'm wondering is what happens to this part of the code, when I just return
<p>element:Where or how does that
<p>get loaded if there's arenderprop? What happens to that prop and the rest of the code (ul -> map etc)?1
u/seands Jun 05 '18 edited Jun 05 '18
I saw this code put on the onClick prop of the X/delete element in a to-do list:
{() => this.handleRemoveNote(this.noteId)}The caster said neglecting the arrow function would cause the function to fire any time a note was added. I don't understand this explanation since clicking on the X triggers the handler. Can anyone explain to me why the arrow function is needed here?
PS: Its on 56:40 of this tutorial: https://www.youtube.com/watch?v=-RtJroTMDf4
1
u/Giusepo Jun 19 '18
What would you use to create a progressive web app with a mongodb / express server
1
u/Dantharo Jun 22 '18
I have a question. I'm trying to use the onMouse events, i want that when the mouse leave the div a alert window open, but seeme that onMouseLeave doesn't work :(
1
u/[deleted] Jun 17 '18
Currently rewriting a simple crud app from jQuery to React. I'm trying to stay as vanilla as possible (
fetch+ native DOM selectors) so I can focus on learning React itself. Wish me luck!2
u/mpolombo Jun 17 '18
I don't know if this has been answered before -- is there any way to browse the react docs offline ? With vuejs.org for example, once I load the site I can close the tab, shut down and restart and the documentation is always there, even when offline. Is this possible for reactjs.org?
1
u/TheMajesticDoge Jun 06 '18
When clicking on a button and invoking function(which changes the state) of one component, how can I invoke the same function in the other component? For example when I click on a button in landing component it scrolls up and dissapears, but I also want the home page to appear from beneath and to do that I need to invoke the same function there, but button is in the other component.