r/reactjs • u/timmonsjg • Jan 01 '19
Beginner's Thread / Easy Questions (January 2019)
π Happy New Year All! π
New month means a new thread π - December 2018 and November 2018 here.
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. π€
π Want Help with your Code? π
- Improve your chances by putting a minimal example to either JSFiddle or Code Sandbox. Describe what you want it to do, and things you've tried. Don't just post big blocks of code!
- Pay it forward! Answer questions even if there is already an answer - multiple perspectives can be very helpful to beginners. Also there's no quicker way to learn than being wrong on the Internet.
Have a question regarding code / repository organization?
It's most likely answered within this tweet.
New to React?
π Here are great, free resources! π
- Create React App
- Read the official Getting Started page on the docs.
- /u/acemarke's suggested resources for learning React
- Kent Dodd's Egghead.io course
- Tyler McGinnis' 2018 Guide
- Codecademy's React courses
- Scrimba's React Course
- Robin Wieruch's Road to React
Any ideas/suggestions to improve this thread - feel free to comment here or ping /u/timmonsjg :)
3
u/seands Jan 19 '19 edited Jan 19 '19
How do you guys avoid coupling your components through styling? I just realized I did this when padding the outer container of a login box component.
My thinking now is to create a
<Spacer>component that accepts props for margin/padding. Then App.js can control positioning which is probably the chief coupling concern.3
u/driedmangoandapricot Jan 25 '19
I have recently just built my first ever React Web App, is it ok to post on this subreddit or is there another subreddit or website where we are able to host to get feedback and just showcase work?
3
u/badboyzpwns Jan 28 '19
Newbie question, I've learned that data in React 'flows-down', from parent to child via props. Would it also be okay if data flows-up? From child to parent? (for example, when you click a button, background color of <body> changes)?I'm assuming that it's poor practice because no tutorial online has recommended me to do this, not for-sure why though!
3
u/greatfool66 Jan 28 '19
I have a project with a React frontend and Node js express backend on AWS. Right now all the api request URLs to my backend are hardcoded at the top of my React components like this : const HOST = "m02-def.us-west-1.elasticbeanstalk.com". I want to refactor to have like a Hosts file somewhere I can import and just change in one place if I need to target localhost backend, is there a good name/place/convention for this file or an I missing something?
2
u/seands Jan 03 '19
How often do you use static methods in React? I have never used one yet. Seems there's no need to assign a method to the class (that I'm aware of)
2
u/caesium23 Jan 04 '19
Where is a good place to ask Redux questions? I tried over in r/reduxjs, but have gotten no responses. (Possibly because my post was unreasonably long, but I couldn't figure out how to explain what I was trying to do more succinctly.) I'm also concerned that my question isn't specific/objective enough to be acceptable on StackOverflow.
2
u/badboyzpwns Jan 20 '19
Should you always use PureComponent to avoid re-rendering issues when a prop changes?
2
u/seands Jan 22 '19
Is there any common use case for the constructor these days? Seems assignments to the state variable and implicit method binding have phased it out of my code, in little projects anyways.
3
u/DrSnackrat Jan 28 '19
I've just discovered the existence of 'prop-types'.
Is it best practice to always add them to every component that receives a prop?
4
u/pallit Jan 15 '19
Hey! Just about finished my first app ever: https://github.com/0LL1/f-board
I learned a lot making it and will be starting another one soon. Do you guys have any critiques or tips?
1
u/workkkkkk Jan 02 '19 edited Jan 02 '19
Can you have any two variables of the same name in a reducer? I keep getting 'duplicate declaration' errors because I was using the same name for some variables (that are the same) throughout different cases. Example
So I get a 'duplicate declaration' error on tab, id, and tiles. For the action properties I can just not destructure and it works find but what about tiles? They represent the same thing so I hate to have to have a new name for every case I want a copy of my state.
1
u/eyepatch61 Jan 03 '19
Hello guys.. I am facing a huge problem with react components because it's getting complicated as I have many react components in my app.
Problem- actually I am using a victory js react library for plotting graphs.. basically I have a checkbox which selects some parameters and then graphs are drawn between them.. if n number of parameters are selected then nΓn graphs will be drawn but when I am adding some more parameters using checkbox it doesn't draw all graphs properly, instead it takes previous graphs which were mounted before selection of new parameters and add new graphs.. so basically if I have 2 parameters selected then I am getting 4 graphs .. but when I am selecting 3rd parameter it keeps all 4 graphs from before and add 5 more but I want to draw all graphs properly because this adding thing draws wrong graphs for some parameters by obvious reasons. I have separate react component for graph. And checkbox is in separate component which is only for selection purpose. After selection of new parameters a state is changes which stores it's values and then I don't know why it starts rendering graph component without calling componentwillmount of it. I guess this is creating the problem. If anyone here can help , that would be really great for me.
P.S- sorry if I don't sound clear. One can ask for more details and I can provide it. I really need help .. can anyone help please. Thanks and please reply if you have any idea.
1
u/somoakie Jan 03 '19
I'm on a different PC than usual.
When I use 'npm i create-react-app' the only files generated are package.JSON, package-lock.JSON and node_modules.
Usually the React 'Boilerplate' is generated.
What am I doing wrong? (I've tried using npm init in the root folder)
1
u/KaizenLionNinja007 Jan 03 '19
What stack or mixtures of technologies should an aspiring React full stack developer become proficient in for 2019 ? which technologies should I prioritize learning practicing : Mern, GraphQL , PostGres , next.js.
just need some direction i already worked with a node , express, and react but haven't linked anything to a data base.
1
u/zaerrc Jan 05 '19
Hi guys,
I am trying to make a react app which captures users multiple pics, but i need them to be stored onto a folder in my device, how shall i do this. Working in localhost.
Thanks.
1
u/seands Jan 05 '19
Anyone put variable assignments inside of render()? I see this a lot and am curious why its done.
As for my reason to avoid itk I think of render as purely for code that renders to the browser. Mentally I like to keep division with assignments/definitions and UI output.
1
u/seands Jan 17 '19
Can you guy advise me on how you hunt down an issue-causing CSS rule?
Looking at Chrome's inspector I haven't been able to narrow the problem. The output is too hard to parse. I use stylesheets and Styled Components library.
1
u/watchscss Jan 19 '19
I host my personal website on Netlify and it's great. But where can I host my two React apps that I made? I want to show them off online somewhere...
1
u/Low-Key-Hipster Jan 20 '19
Iβm struggling with connecting Firebase to my app. Iβm also using Redux. Are there any good resources for connecting your Redux store and actions to firebase?
1
u/seands Jan 20 '19
I see my prop passing down correcting inside react inspector. But the child doesn't render it:
The h5 tag renders when I simply hardcode a string/text without props.
Am I missing something?
1
u/jag_N Jan 20 '19
Hello I was just wondering which way is recommended when adding an item to a state array? Basically use this.state.arrayName or prevState.arrayName?
https://paste.ofcode.org/Ycgx5RnWZbKtYc7ymnptgk
1
u/tubehacker Jan 22 '19
Hi,
Redirect onClick
How do I change to a different route using a button onClick? I have a sign in page "/signin" and I wand to redirect to the home page "/" when the user clicks on a button. Thank you
1
u/seands Jan 23 '19
Any idea why this Styled Components code is acting unexpectedly? Intent is to give a right margin to all but the last child:
Removing the :not selector and () around :last-child then causes the rule to ignore. My syntax must be off somewhere
1
u/seands Jan 24 '19
Is this code wet or is this about as dry as you can get in React?
1
u/sggts04 Jan 25 '19
What is Redux?
Whenever I try to watch basic react videos, the guy tries to insert redux into it.
1
u/sggts04 Jan 25 '19 edited Jan 25 '19
So for my second React App(first was todos), I made a weather app where you can search the location, change temperature unit, toggle for current weather or forecast weather. http://weather.shreyasgupta.in I'd love some feedback. Also after searching it suggests you a location near the location you searched. Also, if the thing that came up isn't what you wanted to search, try searching 'City, State' or 'City, Country' or even a US/UK (only) postal code would work.
Also the api key is easily visible when I inspect element and go to the js file, how do I hide my API key in an only frontend app? I know you can't really hide KEYS in frontend but what if its an only frontend app and the api I'm using doesn't ask for allowed call urls(cors headers)...
Thanks!
1
u/RedditAcctsInLrgAmts Jan 29 '19
I have an app I'm developing. It was started with create react app. I want to try writing some components with hooks. How can I switch to using react 16.8.0 alpha? I installed 16.8.0 with npm, but the app stubbornly remains on React 16.7. I can't find anything relevant to specifying the react version in the docs, npm, or stackoverflow.
1
u/seands Jan 29 '19 edited Jan 29 '19
If using a <BrowserRouter> to wrap everything in App.js do you still need withRouter to wrap the component? I read that no, they do the same thing. Problem is I can't access the history object:
1
u/JavaVista Jan 29 '19
New to react and still a student of JS. Need a little help on why my toggle function does not work from my component and gets added to my aside element to display a side menu. It works on other elements like the header.
Here is my component with the toggle function:
Here is my github that shows the other components:
GitHub Link
1
u/somewut_anonymous Jan 30 '19
I built a small app for my gym that allows users to "check in" to a parking space and "check out" when they finish their class. I know that state gets reset upon a browser refresh and I am wondering if there are any ways to prevent this from happening other than writing a back end for this simple app in the event that someone accidentally refreshes the page and clears out everyone's checked in status. The app is planned to just run on a wall mounted tablet inside the front door of the gym.
I am aware of localStorage but when I tried using it it said localStorage wasn't defined. Thanks in advance!
1
u/soggypizza1 Jan 31 '19
What is the best way to keep a user logged in even after a page refresh? Right now I'm just using localStorage but I've heard that's not a good idea what else should I use?
1
u/[deleted] Jan 31 '19 edited Jan 31 '19
So I have some questions. As someone at their third year on my bachelor I've seen that we get around to submitting more and more web based solutions as assignments. last semester we did an assignment where we had some react in it as well. However I'm pretty bad at anything web based, more like inexperienced, and would like to learn. Preferably ReactJS. I know the basics of HTML and CSS, and have used Bootstrap in some projects.
How would you go about learning ReactJS? Any books recommended?
I've seen the 'new to react' bit and will look at it
Should I try and get really good at Javascript in general before I try to learn ReactJS?
And a React specific question. When creating a React SPA is it normal to have the App return all the components in a flat hierarchy or should I nest components in bigger bits of what the webpage would look like?
for instance I could have several components that make up the navbar, but bundle them into a navbar component, that in turn is rendered by the top-level App together with all the other components.
Thanks for any and all answers!
3
u/OscarArranz Jan 08 '19
After creating a ReactJS app, how can I get it online (I've got a Windows Server 2016 Server VPS), I've always used IIS/Xampp but I doubt they'll work with React
3
u/[deleted] Jan 09 '19
If I were to build a simple static React web app, how would I go about making it easily maintainable by someone else? Ideally I would like to be completely hands off, is that possible (assuming it's bug-free)? Thanks
2
u/nickfoden Jan 03 '19 edited Jan 04 '19
Setting up a form component and my initial state declaration for this form component is getting very long, it doesn't bother me and it works, but wondering what other people are doing when encountering forms with dozens and dozens of inputs?
2
u/caesium23 Jan 05 '19
How should I handle storing references to class objects in the Redux store? E.G., I have a collection of Widget objects, and I need an array of references to them in the store. Is using regular references fine, or would it be better to use some kind of primitive value as an ID and have a way to look the actual objects up using that?
2
u/TeeckleMeElmo Jan 08 '19
I'm starting on my first app that will hopefully be used for a small company. Really simple, just a few static pages then one page with a list of projects, each of which can be selected to open a details page for that project. Since it's going to be really simple, and stability isn't a huge factor at all, would this be a good time to learn and use hooks? Is the way they are used now close to what they will be like on release?
2
u/asaf_biton96 Jan 09 '19
Hi, Iβm starting to work on a e-commerce website for a store. Iβm currently considering whether to use a headless CMS (Strapi), SaaS (prismic.io), or build the backend/api on my own.
The client does not have any specific preference, and while I clearly see the benefit of using an Open Source / SaaS solution, I think a custom build would be easier for the client to maintain and I will have more control over the UI.
What is the common approach here?
2
u/biggustdikkus Jan 09 '19
As a somewhat not a beginner, how do I get away from create-react-app? People seem to look down on developers who use that lol..
2
u/seands Jan 09 '19 edited Jan 09 '19
How to set this up in a React SPA? I can do res.json() for the success call. But I'm thinking I need something like failureJSON for axios to receive, and passport-local doesn't showcase that anywhere (documentation is sparse)
2
u/DrSnackrat Jan 10 '19 edited Jan 10 '19
I'm wondering what the best practice is when handling code that isn't related to the DOM.
Should the functions, constants and non-state-related variables exist on the class as methods and properties, or is it best to have them as plain JavaScript logic, outside of the React class?
2
u/hoodlaces Jan 10 '19 edited Jan 10 '19
NODE -> React Question! Hey everyone, I feel kinda silly for asking this, but I wrote a bunch of Puppeteer code in Node to check my law school grades and register for classes (headless of course). Now I'm being asked how to bring that ability to the student body and the only solution I can think of is to build a front end UI (so I'm learning React). Problem is, I'm not totally sure how or if it will even work... can someone clear up the best way to bring node apps to the masses through a front-end UI? (Ex. Students sign in, then sign up for program that checks their grades and sends them an email when a new one comes out). I have it working in Node, I'm just not sure how EVERYONE can use it from a front end UI. APPRECIATE ANY HELP! THANK YOU!
2
u/HUMBLEFART Jan 10 '19
Hi, I was told to post here, but it's more of a webpack/babel problem than react specifically.
Basically I'm getting the following error:
Which I think is a good sign that the react preset I have isn't working.
I have a babelrc that should recognise jsx:
And in my webpack config:
I've verified in node_modules/ that I have the @babel/preset is there. I've tried adding a jsx to the test regex. I've done an rm -rf. I've tried building without an rc. Same result. And I'm not sure what else to try?
2
u/mrbrightsky Jan 11 '19
Hi guys,
First of all let me be clear: I'm a true beginner, I'm aware of this so be gentle if the following question seems...absurd. My only experience regarding React as of now is the first tutorial of React. I've read a lot of articles about it though. My company has worked with a custom-made boilerplate for several years now and we're thinking about updating this boilerplate with a front-end framework. (Our focus is e-commerce so the boilerplate is an amazing starting point for us.) Right now, we're figuring out which front-end framework to use. I'm just trying to read as much about React as possible so we can make an informed decision. The thing is, our whole boilerplate is written with Smarty and I'm trying to figure out a set-up in which we can still use Smarty for back-end code, but use React Components (with Webpack) for front-end.
Is it possible and if so: should it even be done? All that I'm seeing so far, are set-ups without a PHP Template Engine and I'm quite sure that such a template engine is redundant if/when we'd use React.
Letting go of Smarty would mean a huge impact to our back-end developers and they're very much quite happy with how things are going at the moment.
Any help regarding this would really help me.
2
u/jewishgiant Jan 11 '19
So I'm a relative beginner with React, but come from a back-end background so I'm feeling pretty comfortable with props, state, and the data/logic side of things.
Where I'm a bit stuck is on the styling side. I'd like to find a library to use where I can leverage the layout/functionality of components in a library like Material UI while easily being able to override things like color, box-shadow, margin, etc to make the design my own. Is Styled Components the right kind of thing to be looking at?
An example would be buttons -- the default Material UI buttons only have like, a small number of colors available and I'd like to be able to parameterize a customized button with backgroundColor/color props that're HSL based. But it'd still be nice to leverage the Material UI Button variants -- text, outlined, flat, etc
2
u/thebronxsystem Jan 11 '19
Hey all I want to get better at react with bootstrap. I find react-bootstrap tricky because it doesnt have all the fancy classes bootstrap 4 has. Are there any tutorials you guys recommend that I follow and brush up on my knowledge passing props to react-app components etc.
thank you (:
2
u/flptrmx Jan 12 '19
Background: Iβve been learning front end development for a year now with a focus on React. I went through Udacityβs front end developer nanodegree, but it didnβt include much about algorithms. I started reading Elements of Programming Interviews in Python recently, but felt a bit lost.
Two questions:
2
u/caghassi Jan 12 '19
I'm a DBA for a non profit and looking to replace some Access applications that connect to a SQL database on premise with a web interface that connects to the same database. Is react a better option than say for example PHP? Thank you!
2
u/badboyzpwns Jan 17 '19
Newbie syntax question. I was following a video. I have a parent component that defines a function, let's call it functionA().
functionA() is declared as an arrow function. A child component exists here, so I pass functionA() as a prop. I need functionA() for an onclick event that the child component can use.
Why is the onClick for the child component writen like. OnClick = () => prop.functionA(). Can't you just write it as OnClick = prop.functionA()? Since you already declared functionA() as an arrow function.
2
u/seands Jan 18 '19
What can one do when 2 libraries use their own component for something you want the features of both from?
My current case is an input field. Redux-Form gives me a Field component. Material UI gives me a Textfield component.
If there is no way to merge the properties of both into one, I will take the manual option and do the state management manually to keep Material UI.
2
u/watchscss Jan 21 '19
This person has 25 react projects on one page. Sorry for the noob question, but I thought places only allow one app deployment? Anyone willing to enlighten me how I can host 4 of my own on one place? Thanks!
2
u/seands Jan 23 '19
Authenticating a user via cookie this way feels very insecure to me:
Am I wrong about its level of security? If not how would you guys make cookie validation safer?
2
u/badboyzpwns Jan 26 '19
I'm learning in using PropTypes, the instructor said that for performance reasons, PropTypes are only checked in development mode. Wha does that mean? I know that it's always used whenever you load your web
2
u/scaleable Jan 26 '19
Production build is actually a different react javascript file. Youβd serve the production react version .js when deploying your server, and use the dev one when developing locally.
Packs like create-react-app already do that for you.
2
u/crueltyFreeIndia Jan 27 '19
I am learning reactjs (create-react-app) with styled components. Is there a good beginner friendly guide out there?
2
u/maggiathor Jan 27 '19
So I've been doing a few side projects with React right now and I love writing code in React.
BUT Animations and Transitions haven't taken off with me, because I feel like I always write/implement more code for the transition than for the whole component function. This doesn't seem right :/
An Example:
How would you guys build a simple Accordion? I build a component with Title and Content and the content shows based on the components state (show). What would be the easiest way to implement an slideDown animation like in the good ol' jquery days?
2
u/CountingCats Jan 27 '19
Anyone know of a good tutorial for React + Redux + Typescript?
I've been really struggling trying to get up and running with all three, especially when it comes to class components and stores.
2
u/badboyzpwns Jan 27 '19
Say I have written many propTypes for my modules. Should I go to every file and delete them for production? or should I keep them? The user won't benefit from it. If I keep them, I'm not sure if it will be a huge performance issue.
2
u/Exitialis Jan 28 '19
This might be a CSS question rather than a React one so if there is somewhere better to post please let me know.
I have a react component that is making its parent extend beyond 100% width. But the child component does not have any CSS defining its width nor is it taking up all of the empty space created to the side of it in the parent. If I swap the component for <div>test</div> then the problem goes away.
So far I have wrapped the child in <React.fragment> and a <div> that has width: 100% on it. Neither of them solved the problem.
Does anyone have any idea where I even start looking to work out what is causing this?
1
u/PetmePant Jan 03 '19
I have a function to hide and unhide my header by sending true and false value when user scroll down or up. Any idea how can I make the hide to start working only after 50 pixel from the top?
class Header extends React.Component { constructor(props) { super(props)}componentDidMount() { window.addEventListener('scroll', this.handleScroll) }handleScroll = event => { const scrollTop = window.pageYOffset}1
u/Qooties Jan 04 '19
I'm working on my first react app and I'm running into this issue where my text input is losing focus after each letter is added. I've researched the problem and it seems to be pretty common, but none of the solutions I've found have worked. (I've tried adding keys to the text input component calls, making the text input component a PureComponent and adding shouldUpdateComponent() to the text input component) I'm wondering if the structure I'm using is the problem. I have a base component that has all the state that calls a stateless, functionless form component that calls a handful of text input components. When I watch my dev-tools all of the children of the form component are re rendering regardless of whether their props are changing. I don't know what else I should even try at this point.
1
u/stupid-sexy-jake Jan 05 '19
Hi, very new to React (also using Next.js as SEO is extremely important) and I'm already stuck and having trouble googling the solution...
I'm using styled-jsx that comes with Next.js for CSS styling. I'm trying to figure out how to create a typography component to keep my code DRY.
For example, let's say this is all I have in the Typography component:
I then want to be able to use it like so:
I was reading this guide and they do something very similar to achieve their goal:
This works on mine as well if I apply the style inline, but not if I try to apply it within the <styles jsx> tags. Does anyone know why it doesn't work in that section and how to change the code so it does? I'd prefer to have all styling done within the <styles jsx> tag as I'll likely forget to look at inline styles when making changes/fixing errors.
1
u/ZealousRedLobster Jan 05 '19
I'm pretty new to React and I'm currently fiddling with setupProxy.js , but it doesn't seem to be working for me. Here's my file:
It's exactly the same format as what the migration document says to do, so I'm really not sure what I'm doing wrong here.
1
u/illmatic4 Jan 05 '19
How Do I get onDelete to work?
https://imgur.com/a/F9lcouW
1
u/diegodieh Jan 06 '19 edited Jan 06 '19
Where can I find data to fetch into my web? I find my exercises too simple because I have to write my own data.
1
u/seands Jan 06 '19
Is it safe to send an unhashed password from client to server? I am learning about his and I just assumed even with SSL you would probably hash on the client. Here is the example I'm looking at, a react front end with this snippet in an Express backend using bcrypt and Mongoose:
1
u/tienhien1102 Jan 07 '19
hi thank for your kind support, I have a question in reactjs. I have built a site allow can share posts in my site on facebook. Example: if I click to view detail a post and share link this post in facebook, It must show meta title, description, image on the facebook post. But it didn't work on my site. I inspect the code and found full meta tag in page detail. Thanks
1
u/seands Jan 07 '19
Is it technically correct to mark a project as a view if it uses axios to patch requests to the server? If not, what would you call it? I separate my repos as <project-server> and <project-view> at the moment.
1
u/DoPeopleEvenLookHere Jan 07 '19
I'm using semantic ui to use a search function. I have an object with multiple text fields that I want the search to be able to return results from.
The semantic ui docs use lodash regex matching to filter, but I don't see an easy way to extend it to multiple fields, is it possible?
1
u/HUMBLEFART Jan 07 '19
This might be more of a babel question...
I'm getting an error: Cannot resolve module 'react' \src\components @ ./src/components/App.js 9:13-29
And I can't figure out why I'm getting it. My webpack looks like this:
And my babelrc is simple enough:
I know latest is deprecated, but replacing it with preset-env doesn't fix it. Any suggestions?
1
u/gjozsi Jan 08 '19 edited Jan 08 '19
So I'm facing the following problem. I have a Form which is working nicely, it's storing the data in it's own state of course. Problem is client decided to move out the Submit button outside the form. This is a react-native stuff so I have the following components:
So far the FormScreen handled the Submit part, because the FormComponent could call the handleSubmit function whenever the user clicked on the Submit button.
Now I'm stuck, because I don't know any good patterns what should happen if the container (FormScreen) should tell the FormComponent when to submit. So the Submit button itself is moved out from the FormComponent. How do I do that?
(Because in React (+Native) I'm relatively beginner, I just know one way of communication to parent -> child, which is props. But it feels very weird, to have a prop on FormComponent (as a boolean) which the FormScreen should switch if it should submit.... Is there any better way to handle this?)
So the main point, with this change I have to keep the handleSubmit function, but somehow need to access children's (FormComponent) data.
1
u/prshnt Jan 08 '19
Hello all,
I need to have an feature of article download for offline viewing. How should I proceed? Article may have images, Instagram or Twitter widget, YouTube video.
1
u/Jontii Jan 08 '19 edited Jan 08 '19
Hello everyone,
I have a question about class toggling with 3 divs. I want to add "active" as a class if i click it and that's the easy part which I can get working with state. Then I want to click another div and set that one to active which also works with state using "? true : false". The problem is when I have 3 divs. Any Ideas?
Thanks.
Edit:
I tried using setting state by a id from event.target but it's not really reliable.
1
u/bayhack Jan 09 '19
I have a react-router app where I have a component have a
Linkto another component however I keep getting:Cannot GET /job/7where
7can be anyidI have for it.What am I doing wrong? Does every component with a
Linkneed to be nested in aRouter?https://stackoverflow.com/questions/54102507/react-router-link-button-not-with-router
1
u/Barrel_O_Ska Jan 10 '19 edited Jan 10 '19
I am creating a small racing game and using a background image to create a track.
Is there a way for me to bind the position of a seperate image I am animating to the background image?
I find that I can set the images starting position using react-move ok and it looks fine on a full screen but if you resize the screen the image end up off the track to the left.
It's suppose to work like those old horse racing games at the arcade where once started they change their speed randomly as they move across the screen.
1
u/seands Jan 11 '19
Is it wise to push every route change into a history array in redux? I saw this pattern in a few repos. I think it could help with maintaining the user's view after say a logout.
1
u/TeeckleMeElmo Jan 12 '19
Just created my first project using cra2 and using the --typescript flag and it seems to have messed up the intellisense in VS Code. I have a server.js folder located at ./src/server that i'm using Koa2 with, among other npm packages. None of the npm packages have intellisense though. If I type app. it gives no suggestions, even if I hit control-space, while in another project using cra without typescript, the intellisense works fine for npm packages. I know this isn't strictly react related but I feel like a lot of people here probably use VS code and may have experienced this.
1
u/AllHailTheCATS Jan 13 '19
Im iterating out cards as components inside a itemBox to contain them(just a div with className=cardBox).I have the CSS set for itemBox as follows, but my cards wont go to a new line/row when so many cards are added and instead keep being inserted horizontally, how can I display 5 then move them to a new row to display the next 5 and so on.
.itemBox {
display: flex;
flex-wrap: flex;
justify-content: center;
background: #fff;
}
.itemBox>* {
flex: 1 1 200px;
}
1
u/Cryphoenix Jan 14 '19
My state is like this:
class App extends Component {state = {users: [],posts: []I fetch users and posts from here and send them to my state. As you can see, users have id and posts have userId. What i want to do is, linking userid of post to id of user. So when i want to use id: 1 user on my code, i will also have access to userid: 1 posts. Is this possible?
1
u/DeepSpaceGalileo Jan 15 '19
Are there any good guides out there to create a web-based music player that plays music from your personal server like this project from Top of all time? The only ones I could fine are React Native, and the one React guide I found skipped a ton of steps. I am prepared to talk it in the span of a month, I just want to have a cool project when I am finished. I already completed this video lesson and felt like I learned a ton.
1
u/scriptedpixels Jan 15 '19 edited Jan 19 '19
We what about WesBos' course?
Edit:
What about adding Wesbosβ course?
1
u/maketroli Jan 15 '19
Jest: reducer test not passing, returning
{"[object Object]": ""β why?That's what I am getting.
β
This is the reducer:
This is the reducer test:
The action:
And this is the action test:
And this is how I am using that action/reducer in the component:
β
Any ideas about what could be happening?
1
u/RedFoxFinn Jan 15 '19
Uhm. Drove myself to dead end without knowing what to do to fix the situation.. I'm creating web-app (well, part of it) that has two kinds of todo-lists: persistent and temporary (todoList, volatileList). Persistent ones survive the page refresh and others do not, that's the idea. I managed to get it to the point that the lists themselves render but theor contents (todoItem) do not. Also list deleting was a bit of a problem: button to do that did render, but for wrong lists. Also didn't delete the list. Now that I tweaked the functionality to render listItems, now whole app won't render and it crashes.
Question is basicly that how should I create the app to gain these functionalities: -adding and deleting lists -adding and deleting items on list with priority-flagging -rendering whole thing
1
u/kayz1088 Jan 17 '19
I have a delete action that won't work I read through the code like a million times and can't find where my mistake is. Also the onClick is working for the delete icon just not preforming the action from my contacts.js file. This is the github page Contact Manger any help will be greatly appreciated
1
u/lastpeony Jan 17 '19
I am trying to use css transitions in react.I guess the correct way to apply them is to use `react-transition-group` package.What i am trying to do is on click simply display a box and run the animation.
Here react component:
CSS for transition:
In this case nothing happens
1
u/phphulk Jan 18 '19
Can someone please explain to me how footers work in react/gatsby?
I understand I need to create the component, and I need to import the footer into my layout component, but, I feel like I'm missing something.
Can someone explain the concept of how it should work? I can work through the syntax, but I just don't understand the logic of why I guess.
1
u/CrazyEyezKillah Jan 18 '19
Hey all! Check out this code:
I'm trying to edit the filterVenue function so that if I check the box back to checked, I can add events back into the events array in App's state.
1
u/seands Jan 19 '19
In the onSubmit I see destructuring syntax in the 2nd argument of the wrapper function:
{ setSubmitting }Normally the outer function in my code receives an event. I am trying to process what is happening here. I think the Formik library is sending back "values" (which you can rename to anything) in the 1st argument.
And in the 2nd it wants you to destructure a property or method that it (exactly) has named setSubmitting, is that correct?
1
u/[deleted] Jan 19 '19
I've noticed two different ways of specifying a React component. One way is to declare a render function within a class that extends React.Component:
The 2nd other way:
The arrow notation will implicitly return the React.Fragment, but that means the render function for
Indexisn't actually implemented, is that correct? Doesn't that also mean that theBlogIndexcomponent doesn't necessarily need a render function?1
u/seands Jan 19 '19
In React is it better to put an API call through Axios on the form element's onSubmit, or on the button element's onClick attribute?
1
u/Alcohorse Jan 20 '19
Tell me if this sounds basically legit:
* There's a bunch of somethingScreen.jsx components which comprise the whole view (besides the header) and are meant to be shown only one at a time
* Root component App.jsx keeps a state.phase which is a string describing the screen to be shown ("splashScreen", "optionsScreen", "modeSelectScreen", etc.)
* App.jsx's render() is a big old mass of this:
{ this.state.phase === "componentName" && <ComponentName /> }
Is there a compelling reason that client-side routing or some other method would be better for this?
1
u/Giant_Maeno Jan 20 '19 edited Jan 20 '19
So let's say I've got a bit of JSX something like this:
<div onPointerDown={handleClick}></div>
But wait! Firefox mobile doesn't support onPointerDown. So for the same functionality I need to use onTouchStart instead.
I'm already checking if one or both are supported as soon as the page loads. I just need some way to set one or the other to be used throughout the app. I'm wondering if something like this is possible:
const clickFunctionVar = 'onTouchStart';
<div {{clickFunctionVar}}='handleClick'></div>
This syntax, and a bunch of others I desperately tried, doesn't work and for some reason it's been really hard to Google what I'm trying to do here.
I'm not about to put conditional statements for every clickable element inside every damned component just to swap out that one bit. I know there must be a better way.
Checking the event type inside handleClick() and doing nothing if it's A) a touchStart and B) pointerDown is also supported seems hacky and weird. Disabling touchStart completely if pointerDown is supported seems like it could have unwanted effects.
1
u/seands Jan 20 '19
How strict is everyone about DRYness?
I have a loginFormContainer that has 2 children, one for signup and one for login. It is not very dry because it requires a lot more time and thought to rewire the forms in a way to minimize duplication.
I am doing things the intuitive but non dry way and just keeping it wet for now.
Not ideal I know, but I'm curious if this is a minor detail or something seriously looked down on at work.
1
u/Vetches1 Jan 21 '19
Does anyone how or what to do in the event one uses
express-generatorto build an app, and then turn tocreate-react-appto generate a React front-end? Basically I'm building an app and I built the backend first, followed by routing, which was done using Express. I'm now onto the front-end and would like to usecreate-react-app, but cannot do so because the files created fromexpress-generatorconflict (e.g. package.json, app.js, etc.). Has anyone ever been in this situation or know a painless way to combine the two? This is my first web app so I'm not exactly a pro on how to triage this. Thanks!1
u/miststrara Jan 21 '19 edited Jan 21 '19
Question from a newcomer working on her first project: I know there is no "official" file/code structure fore react, but right now my code is a mess. I've stumbled on things like the container pattern, which seem useful, but I'm not sure what good alternatives there are.
What is your preferred way of structuring JavaScript, css and the rendered tags of components and why?
Question number 2: At what point/project complexity does using redux pay off?