r/reactjs • u/timmonsjg • Nov 01 '18
Needs Help Beginner's Thread / Easy Questions (November 2018)
Happy November! š
New month means new thread š - October and September here.
I feel we're all still reeling from react conf and all the exciting announcements! š
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.
New to React?
š Here are great, free resources! š
40
Upvotes
5
u/timmonsjg Nov 01 '18
Posted this 10 hours ago and we already have 11 comments the next morning. Awesome stuff guys!
4
u/wakandabot Nov 05 '18
Is it ideal to start learning react with asp.net core as back end?
Also, is there any good online tutorials to get me started on this?
2
u/haganenorenkin Nov 05 '18
I'm š ting the wesbos react course and i see something intriguing about imports
In his course he defines the class then at the end of the file he does export default Class name
But I tried that and I got an error saying there wasn't a class with that name or somethingš¤
So I had to use export class MyComponent extends React.Component... and so on
Then there was another component, when I imported a component inside another Component it worked using export default ClassName at the end of the file... Why?
2
u/politerate Nov 05 '18
š
https://codesandbox.io/s/0o20p794w0
The state doesn't change from "playing" to "stopping". When I try to change it manually from the chrome react extension, it shows:
Thank you in advance!
2
u/iKenshu Nov 08 '18
I think my problem with react right now is how to structure my project folder for something like a portafolio o simple web page. I know there are thing like containers and components, components are each element of my web(headers, menu, item) but what about containers?
I have some Udemy course about react like Andrew, Maximilian and Stephen. But I didnāt finish any of that yet .-.
2
u/L000 Nov 11 '18
I've gotten decent enough at React but don't have, or particularly want, a personal project. I'd rather contribute to open source using React, that will expose me to more seasoned code and I'll advance faster. Any recommendations of repositories to look for opportunities to contribute to?
2
u/honxyz Nov 13 '18
Hello,
I'm trying to create a nested / stacked menu, similar to IOS , where one menu and its children may have its own children. But I want to just display one menu at a time and navigate back forth through the stack, and not display as one big tree.
I'm trying to do this with react not react-native and havent found many examples, anyone can point me to some articles or has any pointers.
Thanks
2
u/Daejichu Nov 13 '18
I've been working through learning server side rendering with React and it seems a bit complex for the amount of value you derive out of it. Any professionals out there have thoughts/opinions on server side rendering with React?
2
u/i_am_hyzerberg Nov 14 '18
I was just given approval to do a Proof-Of-Concept at work using Storybook and React (we aren't a React shop at the moment). The requirement is from our UI/UX team wanting a library of components that can be re-used throughout our software applications and incremental changes can permeate throughout all apps by updating code in one source.
So my question is, is there a CSS methodology that is primarily used for this type of development? For components in a library that may be embedded in many different applications? I am capable of researching technologies and implementation details for my POC but I'm hoping someone here can just point me in a good direction so I know where to start because there seem to be so many different CSS strategies out there with React. TIA!
2
u/theirongiant74 Nov 15 '18
Will a production build of a file with this code
Include dev.js in the bundle or is it smart enough to ignore it?
2
u/sobralense Nov 19 '18
What patterns should I use for hooks as I already do with Redux for async fetch? Also, any recommended folder organization pattern?
2
u/Bing400 Nov 27 '18 edited Nov 27 '18
There was this guide on how to make show a bike in a react app, the person that wrote the guide managed to upload that app onto the website. I have the react app that shows a bike, how can I be like him and upload it to a website? It's really hard
https://imgur.com/a/9L0rNiX
6
u/[deleted] Nov 01 '18
Im having a hard time wrapping my head around props and state. Is there a specific way that clicked for you guys? I get the gist of it all but I lose it quickly.
1
u/NickEmpetvee Nov 01 '18 edited Nov 01 '18
This react-beautiful-dnd storybook has its code here. The issue I'm having is that this is a flow-based example. I can't just point to the toplevel TableApp in with-fixed-columns.jsx with create-react-app's index.js render statement and have it work. It complains about the included reorder.js.
How do you get a flow example like this working in React in the most simple way?
./src/reorder.jsLine 7: Parsing error: Unexpected token5 |6 |> 7 | <!DOCTYPE html>| ^8 | <html lang="en">9 | <head>10 | <meta charset="utf-8">My index.js:
import React, {PureComponent, Component} from 'react';import ReactDOM from 'react-dom';import {DragDropContext} from 'react-beautiful-dnd';import TableApp from './TableFixedWidth/with-fixed-columns';class App extends Component {render() {return (<div><TableApp /></div>)}}ReactDOM.render(<App />, document.getElementById('root'));I've slightly modified the imports at the top of
with-fixed-width.jsbecause I've added the react-beautiful-dnd module to my environment:// @flowimport React, { Component, Fragment } from 'react';import styled from 'react-emotion';import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';import reorder from '../reorder';import { colors, grid } from '../constants';import type { Quote } from '../types';import type {DropResult,DroppableProvided,DraggableProvided,DraggableStateSnapshot,} from 'react-beautiful-dnd';1
u/[deleted] Nov 01 '18 edited Nov 01 '18
More of an es6 question, but I want to write a small wrapper around the following function:
from
https://mgcrea.gitbook.io/redux-rest-resource/usage/quickstart
to something that... -takes a name, pluralName, and maybe some options -builds a new object from those options, sessionStorage data, adds some custom actions, etc then spits out
types, actions, rootReducerjust like the example. Is this approximately how I should go about doing that?Here is my attempt/thoughts:
1
u/simplisticallysimple Nov 02 '18
I've bought Bootstrap themes online before to customize, and they've all been a breeze to customize (nothing beyond plain HTML, JQuery, some JS libraries, CSS, etc.).
I recently bought one theme, but unfortunately it's written in React JS, which I have no experience with.
Should I learn it (that theme is a sunk cost now), or should I go online to look for a non-React theme?
I'm building an MVP and need to get it out of the door ASAP.
One part of me feels like I should take this opportunity learn React, the other part tells me to just stick with the familiar.
What should I do?
1
u/trollerroller Nov 07 '18
Can anyone provide a good example of why you ever need to do
npm run ejectfor a react app?I've built at this point a handful of react apps and never once needed to 'eject' - sounds to me like it's sometimes a false go-to when something isn't working with dependencies or similar.
1
u/ChangeFatigue Nov 07 '18
Iām currently learning a lot about fetch in React, but it looks like hooks are going to be replacing how data is retrieved? Does anyone have a good eli5 resource on hooks they can point me to?
1
u/Zecuel Nov 11 '18
Are there any libraries out there with icons for programming language / framework icons?
Specifically, I'm looking for icons of Bootstrap, Semantic UI, jQuery and C#.
I've found JS, HTML, CSS etc from Font Awesome / Semantic but I can't seem to find those mentioned anywhere.
1
u/Daejichu Nov 12 '18
Hello! This is eslint and react related, but probably a newbie question: I keep getting the error
However, I tried to use 'prevState' for my callback as follows to no success:
Thoughts?
1
u/manatwo Nov 12 '18
Hello! Appreciate this thread and any help. I'm working on my first React project, a fairly simple CRUD app with some relational models. Basically it goes Menus -> Categories -> Items (eg, "Brunch" -> "Drinks" -> "Mimosa").
I'm working on the screen to build out the categories/items for a given menu and I'm just not exactly sure how to structure the state in a good/idiomatic way. I have an API (menus/:menuId) that returns all the data in nested JSON with one endpoint.
It feels like what I want to do is have one call to populate a "currentMenu" piece of state, but somehow also have that populate the "categories" and "items" state so I can add to/update those individually without re-rendering the entire page.
I've done some research and it seems like I should be using Redux and Normalizr, but I can't quite put the pieces together.
Thanks in advance!
1
u/seands Nov 18 '18
Is importing a Redux store into presentational components and relying on getState() bad? I ask because I assume Redux prefers using mapStateToProps
1
u/NickEmpetvee Nov 18 '18 edited Nov 18 '18
create-react-app comes with node_modules in the .gitignore. Does that mean it's a bad idea include node_modules into your repo?
I was thinking it's a good idea to include node_modules because the specific version of the module is important. In some of my projects we use open source repos that change frequently. It's an easy way to keep team member codebases in synch.
Thoughts?
1
u/Verthon Nov 19 '18
Hello I would like to know how to send state from "BookTable" component to "ReviewBooking" while using React Router?
Thank you!
https://codesandbox.io/s/github/Verthon/restaurant-app/tree/master/
1
u/chaoism Nov 20 '18
I don't know if I can put this question is correct wording. I only have a rough idea as well.
I'm thinking if it's possible to create some sort of game using react. It's nothing fancy, just using a character which carries bunch of attributes, and then bunch of enemies that also have similar attributes and things like exp and loot
I'm thinking about using states to keep track of each identity's stats, but I'm not sure how to make the two characters battle.
maybe a function which links to a button, and for
onClick, it triggers the function that takes in these 2 characters as 2 classes and calculate damage that way?I'm actually not sure if it's doable. Just looking for some ideas to solidify my own. Anyone has done something similar?
1
u/xehbit Nov 20 '18
Working for quite some while with React (mostly just prototyping). However, i love to use a css framework like Bulma.io but i am kinda confused what a good way is to make components with their own styles. Ive seen inline css, extra scss files per component and a lot of other simmalar things and libraries that i got a bit confused what a good practical way is.
So how should i approach this, making those custom styled components by using a css framework like Bulma?
1
u/easylifeforme Nov 20 '18
Can I learn react if I don't really know basic Javascript or should I learn js first?
1
u/seands Nov 20 '18 edited Nov 20 '18
I am passing down 2 dispatchers to the same function in a child component. One passes correctly but the other does not.
// actions.js
Upon clicking the button I get the error telling me the props object is not passing the function:
TypeError: props.dispatch_set_donation_amount is not a function
save_donation_amount [as onClick]
src/components/SelectDonation.js:15
12 | // grab the custom amount
13 | // add to state object
14 | // done in parent
> 15 | props.dispatch_set_donation_amount(amount);
| ^ 16 | console.log(store.getState().donation_amount);
17 |
18 | };
Can you guys see the mistake?
3
u/workkkkkk Nov 02 '18
Not React related exactlyyyy but any tips on how to get started with free-lance / part-time contract work? I've been working as a developer for 1 year, almost entirely front-end and I've started introducing React into my work, and was a mechanical engineer prior. I would love to get some more experience with small projects but don't even know where to start to find such work.
3
u/L000 Nov 26 '18
I recently had an interview using a HackerRank IDE set up with node and react. It was AWESOME. Looking around HackerRank for more like that I can't really find any. Does anyone know where there might be more like that?
EDIT: looks like this: https://blog.hackerrank.com/new-role-based-assessments/
but I don't know if there are any public ones which is a shame.
1
u/fun_guy_stuff Nov 01 '18
I got a couple:
Where in the process of learning React does tooling - rolling custom webpack configs, loaders, etc - become essential?
What's the ideal test project for learning redux?
1
u/goldenmanzana Nov 11 '18
Hi! I am unsure about how react connects up with various backends. Ostensibly, react is for rendering views, but it appears to also function as the controller(with React router) . I've done some node /express /pug stuff, but I cannot get my head around passing data into react. Am I just mixing paradigms? Most use cases I've seen for react are single page apps, yet here I am, writing routes in express... I'm teaching myself and afraid I'm just trying to do something stupid. Node express crud with React rendered front. Any help gratefully received.
2
u/fun_guy_stuff Nov 01 '18
What's a good rule of thumb for deciding when to break down a new component, ie. how much is too much componentizing?
Say:
<CoolForm> <RadFormGroup> </CoolForm>
Why or why not just stash everything in CoolForm?
2
u/prshnt Nov 02 '18
noob question.
I am using api which needs to send current date in body, so I have set a variable which makes it in required date format using new Date(). But after when I make a production build, it works for that day, but as soon date changes, api call fails. How to handle date dynamically?
2
u/NickEmpetvee Nov 04 '18
I've had a tough time the past few hours with nested JSON in React. I'm trying to parse it the same way I would in native JavaScript and I think I'm doing it right. However React has been complaining consistently.
The codesandbox attempt is here.
This is the JSON:
const initialData = [{project: {name: "Inventory Replenishment",steps: [{ id: 1, task: "Review warehouse inventory" },{ id: 2, task: "Calculate subliminal inventory levels" },{ id: 3, task: "Confirm budget" },{ id: 4, task: "Order goods to replenish inventory" }]}}];export default initialData;In the return():
{/*THIS WORKS - Proving that the JSON is accessible*/}<h1>{JSON.stringify(this.state.data)}</h1>----{/*THIS COMES BACK UNDEFINED - Trying to access the name of the project which is in the JSON*/}<h1>{JSON.stringify(this.state.data.name)}</h1>---{/*THIS SAYS Cannot read property '0' of undefined - Trying to access the first task in 'steps' */}<h1>{JSON.stringify(this.state.data.steps[0].task)}</h1>---</div>Any JSON / React gurus out there?
2
u/ECrispy Nov 05 '18
With context, hooks etc, what is the future of React? It was already confusing and now is even more so. React started off as one way to do something and now there are 20.
2
u/[deleted] Nov 06 '18
Complete newbie here. Im reading the stickied Create React Pad and looking at the single line codes. But where do I type these? What do I have to download first? These aren't mentioned in the link.
2
u/Kilbas Nov 13 '18
I was wondering if it is possible to update a components props from outside react and then watch for that change in the component.
ReactDOM.render(<MyComponent str="myString" />, element);
So if I would update str with plain javascript can that be detected in the component?
2
u/vmorka Nov 13 '18
Hello /r/reactjs. I'm learning ReactJS and trying to implement Redux to my small college project. But I'm getting this error when trying to call a function from container component. And I'm not sure what have I done wrong. I hope you could help me. Thank you in advance.
My component
My container
2
u/demonizer123 Nov 13 '18
Hi,
I need a kick in right directon.
I want a <Parent> component be able to advertize it's "services" (e.g method(s)) to its <Children> - but i want to do it in a way that requires as little knowledge of child from parent as possible. So my idea was to have a sort of "api" for the children, so child would need to implement a method which parent will then call and advertise it's "services", but I cannot seem to make it work with props.children. Maybe someone has some pointers?
I have created a simple Cow>Calf example, maybe that explains things better (not a native speaker)
https://codesandbox.io/embed/1o35nx7yrq
thank you
2
u/Zz1995aJ Nov 13 '18
Hi, would any one be willing to give my 2 components a quick code review? It is just over 100 lines.
It is a very basic tic-tac-toe game that I plan to expand on and is very heavily based on the example from the React website. I'm hoping to iron out and learn from any issues that I'm too inexperienced to spot myself.
Game component
GameSquare component
If anyone has the time, I would be very grateful. Be as nitpicky as you can!
2
u/simkessy Nov 14 '18
I want to go through a react tutorial but not one with redux but instead the contextapi. Any good ones out there?
2
u/neonwarge04 Nov 15 '18
I am following a book regarding using Webpack in building react apps. So this is pretty simple so following a lengthy text on the book about this cli 'webpack' it kept throwing this vexing error I can't seem to figure out myself.
https://pastebin.com/sVyBLwQ9
Google yields advance stuff already and I just got pretty started with React. The code was literally copy pasted from the book.
Not sure if I missed anything on my webpack.config.js:
https://pastebin.com/N35UvD4V
Here are the command I ran to get webpack running in my project:
npm install -g webpack --save
npm install -g babel-core --save
npm install -g babel-loader --save
npm install -g babel-preset-env --save
npm install -g babel-preset-react --save
npm install -g babel-preset-stage-0 --save
npm install -g react react-dom --save
I would really appreciate your help if you can point out what I did wrong. I can't proceed onto what I am reading rn.
2
u/seands Nov 16 '18 edited Nov 16 '18
My question is about best practices with component design.
My App.js looks like this:
(Those are mainly Semantic UI React components)
<SelectDonation> will be replaced by other components based on a state variable in Redux. It is a multi-step form. I haven't added the conditional logic yet, right now I'm doing the initial static design.
What is the cleanest way to tie the Header content in App.js to the component being shown?
I am thinking of creating a function outside render() that reads the same state variable and then returns the desired text string for the title. And then inside render: <Modal.Header>{this.select_title()}</Modal.Header>
Is there a better way to do it? Would you just include the <Modal.Header> component in each subcomponent? Seems simpler but also less DRY
2
u/seands Nov 16 '18 edited Nov 17 '18
It seems with styled components I need to do a lot of refactoring because a bunch of component names change. I have since avoided them (in favor of Emotion).
But I know this design pattern is very popular now. So I wanted to ask you guys if you just do your static design and CSS at the same time, or if you just don't mind the extra refactoring time.
2
u/castane Nov 16 '18
Are there any pre-built repositories of something like a create-react-app with included user accounts and permissions? Or do folks traditionally add authentication manually after building a new app with create-react-app?
2
u/Daejichu Nov 20 '18 edited Nov 20 '18
I have mapped an array of policies to a helping render function that will return back an array of JSX's. However, One of the JSX's should contain button that calls another helper function that would take the id of a particular JSX row/id and delete it (onDeleteClick()). However, I'm blanking on how to pass the id to the helper function onDeleteClick() through the button JSX tag
Render Helper
again, is there a prop or parameter I need to give to the onClick prop of the button? each map id should be 'policy.resource.id'
Update: I have it passing using the following, but would still like to figure it out without using an arrow function in the JSX
Thanks!
2
u/[deleted] Nov 21 '18
Simple question, how do you guys stay up to date with latest developments in React? What blogs do you use etc.
2
u/NickEmpetvee Nov 21 '18 edited Nov 21 '18
In a React / PostgrREST / PostgreSQL stack, what are some approaches to consider for application authentication? The application is not currently integrated with Active Directory, and there's no requirement yet to integrate with any type of SSO. However, would like a method could be expanded into those areas. I imagine in such a situation a user table could reside in the database and we could leverage JWT or something similar.
Tutorial links welcome.
2
u/seands Nov 23 '18
For anyone who uses functional components to style HTML elements: how do you attach refs to them (or do you never use refs anymore?)
I needed to attach a ref to an input to send it to Redux. Semanti UI React's <Form.Input /> caused errors until I changed it to an <input>
2
u/PollenX Nov 24 '18 edited Nov 24 '18
I'd like to create a game that uses canvas and react elements. Are there any pitfalls I should be aware of? If I embed the canvas in a react component will that bind the refresh rate to the rest of the dom, and is this a bad thing?
2
u/seands Nov 24 '18
I have a multistep form where the first step gathers info and sends it to Redux. The last step will send a POST request to my Express back end.
As I think through how to send the data, I think the answer is to bind the redux state variables to hidden inputs on the form on the final page that sends the post request.
Is this the best way to do it? Feels a bit wet to me so I thought I'd ask
2
u/jdelgad8 Nov 25 '18
I already created a single page app, but now i need to change between different pages when i click a button. I have no idea how to do that. Any help would be much appreciated
2
u/benaffleks Nov 28 '18
hey guys quick question for ya
How do you use React to sytlize a page with CSS? It just doesn't make sense to me to use JSX to like create a whole list of tags and then inline stylize them, it just doesn't seem like thats the best approach.
Do you basically just style your elements normally with CSS, and then with JSX you would somehow call the element that is already on the dom?
2
u/Jerky777 Nov 28 '18
Hello, this is react course question. So i narrowed it down to Wes Bos' course, which is 5 hours and costs 70$, and Max's course on udemy, which is 34 hours and costs 10$. You can probably guess what worries me. Everyone says both are great, but how can one fit everything in just 5 hours, while the other is 7 times as long? Is Max just babbling and going on about things that don't matter, or is Wes Bos cutting corners?
I want the best and most time-efficient course to get to junior dev's job-level knowledge. I'm okay with paying 60$ more for Wes' course, if it's going to teach me that much faster
2
u/ivaardfury Nov 28 '18
Hi. Iām building a site using Meteor, MongoDB, React, and Chartjs2.
I have a line graph built, but canāt seem to find a good tutorial or source for how to display my mongo collections in a line graph. Can somebody point me in a good direction?
Iāve been guessing my way through this using a variety of tutorials and the documentation but Iām just not getting anywhere. Examples would be great but I canāt find any. Iām basically losing my mind at this point.. hours of wasted time behind me.
All the data is successfully being inserted and retrieved/displayed, but Iām completely lost when it comes to the chart aspect of it.
Any suggestions? Anything helps!
2
u/[deleted] Nov 29 '18
Is there anything wrong with combining inline styles and CSS Modules? I have CSS Modules set up for most of my project, but I also need to set the row span of a grid item dynamically based on the length of the content.
2
u/dangerzone2 Nov 29 '18
Whats a "pre-bound action creator" look like? I saw a component example in https://blog.isquaredsoftware.com/2016/10/idiomatic-redux-why-use-action-creators but there is no code example for the actual "pre-bound action creator". In the below example, what would `action1` and `action2` look like?
1
u/TeeckleMeElmo Nov 30 '18
Not so much related to react but more to styled components which is a part of the react ecosystem. Anyone have any good recommendations for up to date CSS courses or tutorials? Also is it possible to use CSS libraries like bootstrap (I know there is a react library for it, just using it as an example here) with styled components? Thanks!
1
u/HumanFromSweden Nov 03 '18
How do we do forms in the react? You only gathering inputs values with onChange and make a post request?
1
u/skdoesit Nov 03 '18
I have a component that receives a prop from a parent component, and with that prop I fetch data using axios. According to react documentation, the best place to do the fetch is in the componentDidUpdate lifecyle method, but this unfortunately always causes an extra re-rendering. Any way to avoid it ?
}
1
u/Deadmeat48 Nov 04 '18
I recently migrated a create-react-app to typescript, but my scss files are being ignored in the .tsx components. I'm importing the files like so:
import './styles/scss/style.scss';this worked fine in javascript. I've already installed node-sass and even tried installing @types/node-sass. Any way to fix this without ejecting?
1
u/pangolino91 Nov 04 '18
Hello! I have a question regarding forms / data fetching / POST /GET requests.
In Node.js making an http request in kinda easy. I download npm mySQL and then I simply connect with my database (I am using Hostgator as provider) and make the requests I want.
How to do it in React though? I have a bit of confusion in my mind on how exactly we communicate with the database. Let's suppose I want to create a form in my component and when I submit the datas they get stored in my Database. How do I connect with the database? I tried with fetch() method but I get lost in the syntax:
āfetch('https://mywebsite.com/endpoint/', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ firstParam: 'yourValue', secondParam: 'yourOtherValue', }) })
What should I write in the website url? the address of the Hostgator website? Where do I put the password to my database and where the user?
Sorry for the newbieness of the question but I am really lost...
Thanks in advance
1
u/ambiguousphoton Nov 04 '18
When using React Apollo, is it better to put frequently used queries in a react context and then call the context as needed or is it better to call the query using a query component in all the places that you need it?
Iām trying to get a sense for how a context is best utilized in a GraphQL app.
1
u/i_am_hyzerberg Nov 06 '18
Did a quick search and didn't find what I was looking for so asking here...if I want to call some handler when the enter key is pressed in a text input, are there any performance concerns I should be aware of when using key press or key down? Seems inefficient to call the handler for every key press when only handling enter key, but I don't really have a better solution so thought I'd see if there was something I'm missing...or if I'm just overthinking this.
1
u/throwaway555554321 Nov 06 '18
Does anyone know why
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events[0]($0)allows me to access other instance values in React 16.7 Alpha but not in earlier versions of React?1
u/soggypizza1 Nov 06 '18
Is there a good tutorial on how to hook up react with node? I've done a few react projects but never worked with backend or node before and want to start.
1
u/workkkkkk Nov 06 '18 edited Nov 06 '18
I'm using React with Redux and redux-promise. How do I use createStore() to load in an asynchronous preloadedState?
My entry point index.js file looks like this (minus import statements).
How would I do an async call and set preloadedState to the data retrieved from the call? Where would it go? It seems really silly to wrap the whole thing in a promise and only execute the above code after with a .then() or whatever. I'm sure there's a more proper way to do it?
Edit: My other solution was to just make a 'loadInitialState' action and call it in componentDidMount of <App />
1
u/trollerroller Nov 07 '18
haha, yeah, not having SASS support would be a good reason to eject.
I guess Iāve been only using CRA since around this time last year, although looking at the release history it seems like that was also a lot of 1.* versioning... i donāt know, maybe iāve just been lucky.
1
u/seands Nov 07 '18 edited Nov 07 '18
I am totally new to Redux and also coming back to React after a 4 month break. Can anyone spot the issue in the code above? Here is the other code I added:
1
u/Zecuel Nov 10 '18 edited Nov 10 '18
Might not be react specific, so I'll post somewhere else if there's a better place.
I'm trying to have a page where I have 2-3 containers with fixed sizes (450px wide each), but i want it to be responsive. As in, a 1920px wide screen can fit 3 containers, but a 1000px wide screen can only fit 2, 700px only one... etc. Currently my containers are side by side and overlap eachother on smaller resolutions instead of having them break into separate lines.
Edit: heavy post fingers. Here are my files:
page.js:
page.css:
1
u/seapprentice Nov 12 '18
I posted this question on /r/nextjs but I don't think that's very active, so I hope someone here can help.
I've been going through nextjs.org/learn, and I got all the way to https://nextjs.org/learn/basics/deploying-a-nextjs-app - where I installed 'now', and ran the 'now' command in my app. Specifically, this step:
https://nextjs.org/learn/basics/deploying-a-nextjs-app/deploying-to-zeit-now
I was given an [myrandomappname].now.sh url, but when I go there, all I see is an index with a file directory (meaning no running app). I thought the idea was that deploying to now would automatically start a build, so I'm guessing a missed a step, but can't tell what, as each time I go over it, I can't tell what happened.
Has this happened with anyone else? What might I be missing? My fear is that there is a step that was assumed anyone going through the tutorial would know how to do it, but I think I just missed something.
1
u/Shadowfied Nov 12 '18 edited Nov 12 '18
React + React Router DOM situation, but probably needs to go server side
I'd like to think my question is simple as it is crucial to make a proper SEO-friendly site using React, but alas, I haven't been able to find anything whatsoever to point me in the right direction.
Using React Router, I have a route similar to /article/:slug/. When you hit the route, I then query the API using the provided slug to match a post. If a post isn't found in the API, the page should 404 (as in sending a status, I have no issue showing an error, but that's not correct). Where do I start to work on this? I'm guessing I'm gonna have to do some server-side for this. I've seen some guides where people literally pull in all posts from an API and then generate routes for that, but that seems brutally inefficient and downright unreasonable for e.g. a news site with tens of thousands of articles.
1
u/NickEmpetvee Nov 18 '18
I'm trying the following AXIOS delete with the goal of deleting a single table record identified by parsedLocationID. It's removing all rows in the table though, not just the one specified.. Any advice? Thanks in advance...
// Deletes the process from the process table and the employee-process mapdeleteLocation = (locationToDelete) =>{const parsedLocationID = locationIDToDelete.split('_')[0];const data = {"id": parsedLocationID};axios.delete('http://localhost:3000/base_location',data).then(response => {console.log(response)}).catch(error => {console.log(error.response)});}1
u/Daejichu Nov 22 '18
Just wanted some clarification as in googling is hard to find this. More of a react/redux question. What is the difference between:
Figure 1.0
Figure 2.0
Assuming our action object is holding a new comment as it's payload. Is figure 1.0 appending to the current state? Isn't figure 2.0 as well? Little confused
1
u/[deleted] Nov 22 '18
I'm developing a playlist generator with the Spotify API. I'm refactoring my code in React and I'm a bit confused about lifting up state with asynchronous calls.
In my App component, I have a loginUser function that authenticates a user then updates the state with the user information. I pass this function down through a nav component to a button component that performs the function then updates the state with the user info. I need to use this user info to re render the sign in button as the user's name and photo.
I've tried componentWillRecieveProps and getDerivedStateFromProps but I'm a bit confused on how to use those and if they're even what I need.
Here's a JSFiddle (it doesn't seem to like the arrow functions though so it doesn't work there)
Thanks in advance!
1
u/joonas_davids Nov 22 '18
I'm a noob with React and web stuff in general. I've got some of the basics down so far.
So, I have a desktop app that's made up of about 30 different "panels" (like 30 different pages with all of them having their own different contents). And I want to turn it into a web app with React front-end and Spring back-end.
So am I supposed to create a single-page app from it? And if yes, how is it done? Like I render the initial mainmenu in my index.js, and then how do I switch between the pages? Is there something like cardlayout in Java that switches the users view to different panels?
1
u/akalantari Nov 23 '18
I want to send a promise down to my nested components which get resolved (or rejected) on the main component.
Why do I want to this?
I have created a sample code for this on code sandbox and would appreciate if somebody can have a look:
https://codesandbox.io/s/045o3w13pw
1
u/seands Nov 23 '18
Is using local state and application state for the same variable always bad?
I am trying to reason through how to get an input value into Redux. If using refs I'll have trouble with attaching the ref to Semantic UI's <Form.Input> component since refs can't attach to functional components. The other option is to bind the input to local state and then move it to Redux.
1
u/seands Nov 24 '18
What do you guys usually prefer for conditional rendering:
or
Asking mainly to impress future interviewers with my thoughtfulness about good code design, although of course having actual maintainable code is also nice to know.
1
u/mynonohole Nov 28 '18
I want to implement a delay rendering of a child component similar to desmos.
(i.e. enter '7 + ' , but don't enter the second number, this causes the error icon to pop up in a delayed style, however if the user does enter another number before the icon appears, then the icon does not render)
I assume I will use setTimeOut but I heard this could cause issues. Does anyone have a general idea of how to do this sort of async rendering?
desmos
1
u/Monstertone Nov 29 '18
Help needed iterating through array to play audio list.
I have an array of URLs for mp3s to play. I can play an individual mp3 with the audio player no problem, but I want to play the songs in order automatically. Is there a way I can make this happen?
Codepen of my simple component.
Here is the code I'd like to apply to make this happen
Is there any way to make this happen in my component?
1
u/[deleted] Nov 29 '18
https://imgur.com/M4nG843
Hey guys I'm doing the 48 video lesson newly posted. Why is the folders different from installing it using a terminal? I am also using atom. Can I accomplish the same things by doing it myself?
1
u/AlarmingNectarine Nov 29 '18
Hey, do any of you know how to call a change function that's on an imported class? I'm trying to call it from a file that has a
constthat has a textbox on it. The textbox change event needs to call the function declared on the class that's imported. Here is my stackoverflow question that shows the code samples:https://stackoverflow.com/questions/53545754/how-do-i-bind-onchange-event-to-a-function-from-an-imported-class1
u/Daejichu Dec 02 '18
So I want to include a sidebar in my React application. I've already built the application, but this would be a refactor. I've researched and found that you can either use built components from a front end framework (Material UI), use a layout with something like Bootstrap to do col-3 col-9, or build from scratch. However, I'm not sure what's the best solution. Any thoughts?
Here is my index.js that is currently routing: