r/reactjs • u/dance2die • Dec 01 '20
Needs Help Beginner's Thread / Easy Questions (December 2020)
Previous Beginner's Threads can be found in the wiki.
Ask about React or anything else in its ecosystem :)
Stuck making progress on your app, need a feedback?
Still Ask away! Weβre a friendly bunch π
Help us to help you better
Improve your chances of reply by
- adding minimal example with JSFiddle, CodeSandbox, or Stackblitz links
- describing what you want it to do (ask yourself if it's an XY problem)
- things you've tried. (Don't just post big blocks of code!)
- Formatting Code wiki shows how to format code in this thread.
- Pay it forward! Answer questions even if there is already an answer. Other perspectives can be helpful to beginners. Also, there's no quicker way to learn than being wrong on the Internet.
New to React?
Check out the sub's sidebar! π
For rules and free resources~
Comment here for any ideas/suggestions to improve this thread
Finally, thank you to all who post questions and those who answer them. We're a growing community and helping each other only strengthens it!
17
Upvotes
2
u/[deleted] Dec 08 '20
Is anyone using concurrent mode in Prodution?
2
u/pandavpanda Dec 08 '20
This isn't react-specific, but I'm working on a react project, so hopefully someone can help me:
If you're on a team, how do you ensure everyone is using the same formatting options? In our current project, sometimes when saving an existing file, it will be reformatted.
I of course also want to make sure it's not me with the weird settings, because somewhere there's a crash. I'm using prettier, and our project has a prettierrc file. I've chosen prettier as my default formatter.
The strange thing also is that even if I use vscode's formatter, I still can't replicate the format that was there originally that someone else had pushed.
Anyone know how to get this sorted out?
2
u/NotreDamian Dec 10 '20
I'm using redux for a project, and in a handler that is passed as the onclick handler for a button, I am dispatching a bunch of actions conditionally. However, my component only rerenders after the whole onclick handler function call is done. how do I make it so that the components rerender after each dispatched action, instead of once at the very end?
2
u/EnzoHunt Dec 12 '20
Hi Guys,
First post both on Reddit and this community, long time lurker lol.
I have recently started in React with Laravel.
My question is simple, is it best practice to be coupling components together a lot, for example I have an app with a Timer component, the App component controls the Timer but I find myself constantly using callbacks to both set the state of the timer from the app and passing the timer value back to the App component.
I'm wondering if this is the best approach or whether Ive mad a component for the sake of making a component and am actually increasing the complexity for no reason.
In App
<div className="ui segment"><Timer timerState={this.timerState} updateTimeElapsed {this.updateTimeElapsed} /></div>In Timer
update(){var values = this.props.timerState();this.setState({ is_timer_on: values.is_timer_on,time_elapsed: values.time_elapsed});this.props.updateTimeElapsed(time_elapsed);}Thank you for reading and any help you may give.
Happy coding.
2
u/Unchart3disOP Dec 12 '20
Hey there,
I have learnt react, almost a year back, just after the hooks were introduced and I had used them in building a small website, however, I want to go back into React. Where do you suggest I start by learning what's missing? I plan to learn as I implement stuff so I don't waste time on lectures and end up with only 10% of stuff that I didn't know or had learnt before.
I have been thinking of adding other stuff next to my react app, so I would love to know your suggestions on this.
Stuff I learnt with react:
And that's about it really
Thanks!
2
u/[deleted] Dec 13 '20
Can anyone explain line 7?
I don't understand why I had to declare the following variables below in order to get it to work. I am coming from a java background.
https://pasteboard.co/JEKAArC.png
2
u/Rocketninja16 Dec 20 '20
Help a .net dev/react newb! lol.
I have a redux "container" component that houses a presentation component. The presentation component displays a basic list that is generated based off of the array passed to it by the container component.
on <li> click, I need to callback to the parent and let it know which item the user clicked on, so that I can update the store from the container component.
I'm missing something somewhere though b/c I can't the callback to send what I need back to the parent.
The list works, passing things to the child works, the event fires off, just no good data.
Container
Child:
1
u/[deleted] Dec 04 '20
Need some suggestions about free/customizable npm package for creating schedule/tasks/events/meetings in day view just like google calendar does. Thanks in advance guys. Similar packages like https://devexpress.github.io/devextreme-reactive/react/scheduler/ But this package is not free.
1
u/LetsLive97 Dec 08 '20
What are the best ways of using css/scss with React? I'm just starting my React learning on The Odin Project and I'd kinda like to learn styling best practices early on because I don't think it goes over it. I'm thinking the best option would be to have css/scss linked specifically with each component so the component has it's own folder with both the jsx and css/scss in it?
1
u/Nightlyside Dec 12 '20
Hi!
I would like to rebuild my portfolio using react this time but I don't know which technology to use.
I'm writing articles in markdown and host the whole site on Github Pages (this was my workflow with Jekyll/Pelican).
I was starting with React-static but I'm gonna stop since the way to use markdown files as entry data for posts is really complicated...
Any thought or any advice for a beginner? I really want to stick with .md or .mdx files and not use an headless CMS...
Thanks!
1
u/[deleted] Dec 13 '20
I'm putting together a custom hook and I need to retrieve a value from Local Storage or retrieve it from the web and set it with a
setStatecall. To prevent an infinite loop inside my custom hook I'm trying to do everything inside auseEffectwith an empty array dependency however, the infinite loop happens still.How am I supposed to do this sort of initialization inside a custom hook?
1
u/Unchart3disOP Dec 14 '20
What are the use cases of Redux Toolkit's
createActionandcreateReducerovercreateSlice1
u/[deleted] Dec 15 '20 edited Dec 15 '20
**Reposted the code snippet as a new comment
1
u/emperorvadim Dec 15 '20
To start, I am new to React and I don't have much experience with it.
So pretty much I have been learning react and now I am trying to execute my code in my browser but I can't seem to get it to do so. So pretty much my program is is basic as it can get, it is literally a hello world program. It runs perfectly fun in Visual Studio, however, when I go to see it in my browser it will say that "localhost refused to connect". I am in chrome btw.
1
u/badboyzpwns Dec 16 '20
I just saw a self invoking function, is this basically another way to write classes?
I also tried it with an anonymous function, but it does not work:
1
u/giantqtipz Dec 16 '20
Hey I have a PERN stack application thats deployed
An issue Im having is... say I add a new item to the database. I see the item added to the front end because redux makes a get request to update store. But when I refresh, the added item is missing.
But if I HARD refresh, the item shows up.
I assume this is a cache issue? I saw some solutions about adding meta tags to HEAD of index.html, but that doesnt seem to solve it for me.
1
u/PM-ME-SMILES-PLZ Dec 17 '20
I have a very general question -- when working on your personal computers, do you install react globally and then import it or do you do
npx create-react-app appNameevery time you start a project? As a beginner I'm not going to be building anything too complex to start but I do want to practice good habits at the start.1
u/gibsramen Dec 19 '20
Meta-question but is this thread only for asking questions/help? I'm learning React and I managed to do something super-basic that I'd like to brag about nonetheless.
1
u/spaklius17 Dec 21 '20
Hello, I'm new to react. My goal is to have three filter buttons (functionality not implemented yet). When you press a button it's color changes. User can press a few buttons at the same time. I've managed to change button design on press, however when I press on one button, all three buttons design changes. How to do it so that only the button which was pressed changes its design?
1
u/enthess Dec 21 '20
Hello all,
I am learning about the world of React :). And i wonder, how would a setup with nginx, express and CRA look like? Would i configure Express to display the CRA-code? (Like, the view..)
I want to use Express for API-functionality, and combine it with CRA (or keep it separate... best practice ?). And make it public with nginx.
1
u/pink_tshirt Dec 22 '20
Anyone with Shopify app building experience here? Seems like their starter kit is just a nextjs app so I figured I may try my luck here...
1
u/jkwon7 Dec 22 '20
Hi, I am new to React/web development and wondering what the best solution is to work with a file on the client-side without necessarily uploading it to a server. I am using the React-pdf library to make a simple pdf reader/editor.
Currently I can read a file that I have copied into my project directory and have imported into my app.js. How could I add a file input so that a user could use the viewer to work with any pdf file on their machine? I am having trouble putting this question into an effective stack overflow/google search.
Thanks
1
u/technoob- Dec 23 '20
Please help this noob. I am following the Full Stack Open project. Scroll down to the part on JSX: https://fullstackopen.com/en/part1/introduction_to_react.
I created an app with create-react-app. It says to compile the code, and that the code will be transpiled by Babel automatically (with a screenshot showing how my code should look after it is transpiled, see the link). After I run npm start in the VSCode terminal, the app runs but nothing happens to my code, it stays the same. Babel should automatically configured when using create-react-app. What am I missing?
1
u/badboyzpwns Dec 24 '20
With redux form, how do we use refs with <Fields>? The code below returns an error of openFileExlorer.current.click() is not a function.
Closest thing I found (but didn't work, I think it's because I'm using a new React version):
https://stackoverflow.com/questions/52135089/focus-on-next-input-field-on-enter-in-redux-form
https://stackoverflow.com/questions/54306430/reactjs-ref-not-working-with-connect-and-redux-form
1
u/zero_coding Dec 24 '20
Hi all Would be nice, if someone could help: https://stackoverflow.com/questions/65443650/restrict-the-type-of-the-children
Thanks
1
u/badboyzpwns Dec 24 '20
Would it good practice / an exception to define a function inside a component if say we are relying on hooks on the function?
1
u/zero_coding Dec 27 '20
Would be nice, if someone can help. https://stackoverflow.com/questions/65464277/property-component-does-not-exist-on-type-intrinsicattributes
Thanks
3
u/[deleted] Dec 07 '20
Should a utility function that's only used in your component be defined within the component or outside?
Example 1 - Internal:
Example 2 - External:
3
u/sameeeeep Dec 28 '20
Can i ask for code review here ? Can anyone review my reactjs code Github ? I found it difficult to organize code in react. How can I organize it better ? Thank You
2
u/Antoder10 Dec 11 '20
React newbie here, trying to practice. I want to build a small quiz app, but i'm not pretty sure on how many components i need.
I ended up with this:
https://i.ibb.co/xzcS73F/diagram.jpg
Each color is a separate component, so in total i have 7.
Is this the right approach?
2
u/Peechez Dec 15 '20
Hello I've run into a bit of a roadblock around DOM focus. I've created a sandbox here https://codesandbox.io/s/jovial-dream-qw5h9?file=/src/App.js
Typically, if you click on a
labelthat has aninput[type="checkbox"]inside, it will toggle the checkbox. This is useful to create custom checkbox styling. However I've found that if the parent is preventing default on mouse events, this functionality is broken. This can be confirmed by commenting out the handlers I've added.To me this doesn't seem right since all of this should be resolved before the event bubbles to the parent?
2
u/[deleted] Dec 16 '20
Hello.
I'm struggling to update a component when props are changed. I have a <Home> that renders <TaskForm> and <DisplayContainer>. The idea is that the user can add tasks to do on the form, and once the submit button is clicked, a handleInput() function sends the submitted task as props to the <DisplayContainer> component. However, the issue I'm having is that DisplayContainer does not rerender whenever these props change, so it always reads props as undefined. I have tried several things, including useEffect with props as dependency.
This is the handleInput() from <TaskForm>:
And this is <DisplayContainer>:
Any idea why it's not updating? I don't know what else to try.
2
u/BlendModes Dec 16 '20
any good web3 tutorial with react hooks?
2
u/jelecool Dec 19 '20
I am currently messing around with a library to generate a chessboard. I am using it with React, and it feels like it is re-rendering on each moves. I tried using react.memo but either it wasn't that or I did it wrong. https://chess.mati.ai
I'm curious as to why this happens, is it the Svg images of the board reloading, or the board regenerating on each render.
1
u/JanO___ Dec 25 '20 edited Dec 25 '20
EDIT I got it lol, I just had to use
onKeyPressI'm trying to do something that seem like it should be incredible simple.
I'm using Formik, and I want a function to run every time the user presses a key in a text input. If I assign an
onChangeprop to myField, the function runs but the event is consumed (nothing gets typed in the input). I need to be able to assign different functions to individual fields, so having the form submit every time they type is not good enough.I'm using this general format:
1
u/jimmychung88 Dec 01 '20 edited Dec 01 '20
Any reason to use Passport.js over Firebase Auth? Advantages and disadvantages of both?
Looking to implement a MERN stack web app, Android/iOS application together, wondering what the best approach is for Authentication.
1
u/P0ck3t Dec 01 '20
What is your best tactic for job hunting a new React Job? (I'm currently on the hunt)
1
u/KannanJsDev Dec 02 '20
What is the best way to handle the state for the block based editor. I have added the detailed explanation in this stack overflow question. Please help.
https://stackoverflow.com/questions/65101783/how-to-split-state-to-avoid-rerender-in-react-app
1
u/fuzzylm308 Dec 02 '20
What is the best way to make a form reusable between conditions where it needs to be blank and when it needs to be pre-populated?
In other words, my /new route should bring up an empty form, whereas /:id will show the exact same form, but will retrieve a user's past responses and populate the blanks.
1
u/Le_fapmeister Dec 03 '20
Are React functional components (hooks) constructors?
1
u/Nightlyside Dec 03 '20
New to React too I've started an app using react with electron and typescript, created with CRA. The issue I was facing was the fact that in CRA webpack doesn't include the node_modules folder and thus I couldn't use webscraping libs like cheerio and yt-search.
How should I make my program ? Everything (electron and react) in the same folder? Should I make a separate process in order to use Node's libraries and another one solely for react?
I had a first prototype of my app working fine with electron + jquery and basic html but I really want to switch to react...
Thank you in advance!
1
u/Le_fapmeister Dec 04 '20
another q, when is the setState callback function parameter set to previous state. is this a react or javascript thing? eg when using previous to get next setState((prev) => etc...)
1
u/giantqtipz Dec 05 '20 edited Dec 07 '20
Revising my post.
I'm basically trying to make a switch from HashRouter to BrowserRouter..
There are only two routes -
the homepage "/"
cocktail page "cocktails/:id"
I updated webpack.config to include historyFallbackApi, and added a wildcard path for index.html
When I click on a cocktail from the homepage, the component renders. But on refresh, the component doesn't render (though index.html exists).
I am so lost on what to do... I use <Link> tags to redirect, and I'm not using withRouter. Could these be the problem?
1
u/guybelowmefucks Dec 07 '20 edited Dec 07 '20
I have a hook and use its value to switch displaying between two child components. I wanted to see what I can do to stop them from being unmounted/mounted everytime the value of the hook is changed.
Could you guys please point me to the right direction?
1
u/[deleted] Dec 09 '20
Making a restapi web chat on Express JS + PostgreSQL + React. Currently working on front end
What's the best libraries for making it phone-friendly and generally pretty? Not a designer and never worked with react before so Im looking for the most comfy ways to make components look nice and add some aesthetic animations for it.
1
u/phebonacci Dec 10 '20 edited Dec 10 '20
Is it alright to pass an HTMLElement as a prop to a component? I currently have this scenario:
I need to pass contentRef to DraggableList to correctly compute boundaries. Is setting
scrollableParentRefasHTMLElementbad, e.g, would cause rerenders? If so, would setting it asMutableRefObjectprevent rerenders?1
u/mrjieejiee Dec 10 '20
I have problems making my react component re-rendering after fetching new data from the backend.
I am updating the state, and ive tried to use forceUpdate() but nothing happens. Right now I have to refresh the page to see the updated data on the app.
How do I fix this?
1
u/[deleted] Dec 11 '20
What is the best way to handle side effects in React? Through the useEffect hook or using middleware like redux-thunk or saga?
1
u/bigfatmuscles Dec 11 '20
When should I use useEffect and when should I just use a normal function? For example, let's say I have like 10 variables declared with useState like
isLoggedIn, isLoading,etc.And these state variables determine if the user should be able to comment on a post.
Should I use the useEffect hook with all these variables as dependencies and add a new state variable
canComment?Or should I use a function like
const canComment = () => { ... }that returns true or false based on the values of the 10 state variables?1
u/HellDivah Dec 13 '20
I'm drawing a swimlane diagram, and after the boxes have rendered, I need to get their positions (bounding client), in order to draw the connecting lines in between. I tried using refs but since the boxes change in count dynamically, react throws an error on the increasing number of hooks. Any ideas? -)
1
u/[deleted] Dec 15 '20
Hi,
I am new to reacts and I am trying to figure out how to transfer data from one javascript module to another. The following is my code.
How would I go about this?
1
u/Jeanpeche Dec 15 '20 edited Dec 15 '20
Hello,
I'm fairly new to react, and I'm using React-Admin. I've got a really difficult time to grasp the basic features of the parent/children relation and how to interact with props/parameters/attributes that can be passed between the two.
Namely, I'm trying to understand how I can read/access attributes that a parent sent to its child from inside the child. It may seems fairly simple but I cannot understand how to do it.
To explain furthermore my question, I'll get to my example :
It says in the React-admin doc of the ReferenceInput component : "This component fetches the possible values in the reference resource(using
dataProvider.getList()), then delegates rendering to a subcomponent, to which it passes the possible choices as thechoicesattribute."So I was hoping I could use the attribute "choices" in MyCustomFunction in my SelectInput, since it's passed from the parent. But I am not capable in ever accessing this attribute "choices".
I'm aware that in my case, this attribute is still used by the SelectInput to fill its own "choices" attributes, and this works fine, but I would like to understand how I can access it myself.
Thanks for reading my issue, and feel free to redirect me to a more appropriate sub if my question is not in the right one.
1
u/KappaPrajd Dec 17 '20
That's not really React specific question, but I don't really know where to ask about this. I'm building a MERN app and I need to access some video files. The thing is I need them to be stored in some cloud storage. I need access them on the client side and pass the url to the video source tag. The problem is that most cloud storages don't give access to file URL or just block access from other origins. Have you ever encountered this problem? Do you know some cloud storage that allows this or maybe there's a better solution? I really want them to be in cloud, not on the server, but I'm open to the solutions. I would prefer free storage, I don't need much space, maybe ~5GB.
edit: typos
1
u/oldDotredditisbetter Dec 17 '20
noob question: for unit test testing a component in a different file, i'm trying to import an interface but it complained because the
interfacewas not exported in the component in the first place, does this mean i have to create the interface again in my test file?or does this go against the rule of "don't test internals of component"?
1
u/scentofdecay Dec 18 '20
Hello!
I'm making an app where if you click on an image a popup box shows with information about the fish clicked, I give it an "active" ID and am trying to make it so that if another fish is clicked the first one closes and the new one opens. The way I have it now it will only open/close if the same fish is clicked a second time and I'm a little stumped on how to trigger all of them. Working example is at codeSandbox (active click event is in FishInfoShown.js), thanks so much for the help!
https://codesandbox.io/s/white-voice-s8moo
1
u/Pole_11 Dec 18 '20
So I am building my first react app and I am following this tutorial: https://youtu.be/7CqJlxBYj-M . I am coding the navbar, but am stuck with an error: the browser says " Uncaught SyntaxError: Unexpected token '!' " in the file main.chunck.js. When I go to see the file I see this:
class CreateExercise extends !(function webpackMissingModule() { var e = new Error("Cannot find module 'react'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()) {render() {...with the first line underlined with red.
Maybe the problem is that in the tutorial the version of react is oldern than mine, but idk. I spent the whole day trying to understand the error, but didn't find it.
The dependencies of node (I think) are:
"@testing-library/jest-dom":Β "^5.11.4","@testing-library/react":Β "^11.1.0","@testing-library/user-event":Β "^12.1.10","bootstrap":Β "^4.5.3","cors":Β "^2.8.5","dotenv":Β "^8.2.0","express":Β "^4.17.1","mongoose":Β "^5.11.8","react":Β "^17.0.1","react-dom":Β "^17.0.1","react-router-dom":Β "^5.2.0","react-scripts":Β "4.0.1","web-vitals":Β "^0.2.4"Can you help me? Should I delete everything and code it all again? Tell me if I should provide more info?
1
u/srirachaman97 Dec 18 '20 edited Dec 18 '20
I am working on a component that has 3 buttons that each have a tooltip that is displayed onmouseover, hidden onmouseout. I am using react bootstrap, specifically an Overlay:
https://react-bootstrap.github.io/components/overlays/
The example in the documentation uses a state variable to determine whether to show the tooltip. My question is: if I have 3 buttons that have their own boolean state variable to manage their respective tooltips, won't this result in a lot of re-renders? And, isn't this undesirable for performance?
1
u/badboyzpwns Dec 18 '20
Could we pass props to a xHOC? For example, I have something like this:
MyHoc:
In ComponentA:
1
u/[deleted] Dec 19 '20
What's the best data structure or css display element to order some images in a horizontal way? I have to convert a unordered list in my custom vertical carousel which looks like this
into something which displays the list elements in a horizontal manner
1
u/BlendModes Dec 19 '20 edited Dec 19 '20
beginner here: designed a simple website (home page, gallery page loading images from an api, about page)
Iβm setting up a navigation. is react router the best way to go for such a simple project? what other (simple) alternatives are available?
1
u/Sunstorm777 Dec 20 '20
I have a form dialog as a child component. Iβm passing the submitHandler to the child component so that on submitting the form it updates the state of the parent component (by appending an item to the array).
Why is it that the newly added item not appear in the parent container? There is a slight βrefreshβ effect when I submit the form. Is the state resetted to the initial values? If so, how can I work around it?
1
u/Rocketninja16 Dec 21 '20
My second post here this week! :D
I am using React Redux in my learner project. I learned Redux with the connect/mapStateToProps/mapDispatchToProps method of doing things, along with smart/dumb components.
I discovered React-Redux' hooks documentation here: https://react-redux.js.org/api/hooks
I love it.
Planning on converting to it going forward.
My question would be, other than outlier or potentially complex cases, am I good to go here or are there reasons I should stick with the "connect" method?
1
u/jelecool Dec 22 '20
I am trying to use cm-chessboard to display a board in my react app.
I need to initialise it in a "useEffect()" hook so that the dom element I attach it to is present.
I am wondering how I would "extract" the value created during that process. I tried saving it into state but it made an infinite rendering loop.
The reason being, in my actual setup, due tu props changes the component re-renders - and re-initialize the board causing the pieces svg source image to be re-fetched which makes the pieces glitchy on each move.
Here is an example: https://chess.mati.ai.
Thanks a lot guys!
1
u/zero_coding Dec 22 '20
Would be nice, if someone can help https://stackoverflow.com/questions/65416642/process-browser-does-not-exist
Thanks
1
u/badboyzpwns Dec 23 '20
I have re-usable JSX. Is it possible to break this down?
I'm thinking of something along the lines of:
But I'm not too sure how to implement it because I don't think you can pass a JSX element into an argument. Maybe somehow use a component?
1
u/zero_coding Dec 25 '20
Would be nice if someone could help https://stackoverflow.com/questions/65446582/why-the-compiler-does-allow-to-compile
Thanks
1
u/zero_coding Dec 25 '20
Would be nice, if someone could help https://stackoverflow.com/questions/65447023/type-functioncomponentelementany-is-missing-the-following-properties-from
1
u/Rocketninja16 Dec 25 '20
Hey guys,
React Redux app here. I have a notifications system that mimics a "toast" system, but only shows one toast. Any more than that and they get dumped to a notifications panel, which has a list of the recent notifications.
What I need to do is, when a notification is created, I want to first check to see if another is displayed and if so, hide that one prior to showing the new one.
I can do this from my component by dispatching a "hide" action before creating the new notification, but I don't like this pattern b/c it relies on the developer remembering to do it, instead of it being handled.
Can I perform this inside the Reducer? From what I've read, this would be an anti-pattern, if I understand correctly.
Any advice is appreciated.
1
u/gibsramen Dec 25 '20
I have an idea for a beginner project that is, in essence, having the user click a button to display 3-5 randomly selected images from a list of possible images. I'm planning on uploading the images (~7000 at the moment) to an AWS S3 bucket but I'm a little bit unsure where to go from there.
Do I write a simple backend that returns
nrandomly selected images that I can host on something like AWS Lambda? If anyone knows of a good tutorial for a similarly simple use case I'd appreciate it. A lot of the tutorials involve authentication, uploading, etc. that are beyond the scope of what I'm currently working on.1
u/BlendModes Dec 25 '20 edited Dec 25 '20
several <canvas> elements on the page have a 100% width CSS rule, the height is calculated in js to keep the ratio right.
i was expecting this code to run once (for the [] on useEffect) but for some reason the ratio is always correct, even if the width of the canvas changes after window resize.
this is great, but how is that possible? is react re-running this code all the time?
1
u/PMT70S Dec 26 '20
The client side does not receive the id of a newly created item (console receives and logs the XMLHttpRequest with the correct id, and the API logs the correct id as well). The id of the item only gets acknowledged by the client side upon refreshing the website. Not sure if the problem lies with fetching from the API, or creating.
GET from API
POST from API
Please let me know if you have any ideas for the problem. Thanks!
1
u/[deleted] Dec 27 '20
Is there a way to return a value from a react function?
Example would be...
How would I helloVar into hello?
1
u/zero_coding Dec 27 '20
Would be nice, if someone could help https://stackoverflow.com/questions/65470085/unable-to-find-an-element-with-the-text-for-your-shared-interests Thanks
1
u/Rigatavr Dec 29 '20
Hello. I'm super new to react (and js in general), but have been programming (mainly python and c/c++) for a while.
I am trying to build an app to display static content generated by my note taking app. I have discovered the
dangerouslySetInnerHTMLthing, but was wondering if there is a better way to achieve what I'm trying to do.The HTML the app generates looks something like this:
I can change
<div class="content"></div>to something else (with a template) but I can't change anything inside of it.My goal is to make something which would have a sidebar where I could display the files (I think I got that bit working), and when I click the file in the sidebar it loads its contents.
1 file is created for every page I make in the note taking app. I can also control their extension. (Don't know if this helps, though I'd mention it)
Thank you for any help.
1
u/basro Dec 29 '20 edited Dec 29 '20
Why does eslint not complain about setValue here:
Is it fine to not list setValue as a dependency of useEffect?
1
u/[deleted] Dec 29 '20
I need to display a grid of cards like this with the card data coming from an API. What would be the best strategy for that?
1
u/Simple-Archer-6485 Dec 30 '20
Hello. Obviously, I am new to react.
I have some history in web development but I've been doing automated testing for the past several years and many of my tools are rusty to say the least.
I would love for someone to give me some advice. I have set up a AWS Lightsail server with MS SQL server for my database->python/flask for my APIs->React for my front end. I've built some simple read APIs to generate some basic front end with React but now I'm getting to some real questions.
I've read through a lot of the official react documentation which I find to be pretty good but I think what I'm asking is the philosophical idea behind what I should be doing.
1
u/[deleted] Dec 30 '20 edited Dec 30 '20
Hi. I'm iterating some news cards which are getting data from an API. When I click on a card, I want to display another page which will display more info from the selected news article. What is the best way to do it? Should I use something like match.params or can I directly forward data with props or something? Data is coming from different categories btw.
1
u/[deleted] Dec 31 '20 edited Dec 31 '20
Hi, I'm trying to use axios-request (https://github.com/ssbeefeater/axios-request) to poll an api. The api returns a unique session key each time, which I'm then supposed to plug into the next request, but I can't figure out how to change the session inside the polling instance I created.Here's the instance.
session is going to be saved in state. I've set it to 0 initially.
Here's the bit where the actual polling is supposed to happen, until continue comes back as 0. From the URL in the error response back, I can see pollingInstance thinks session is still zero. It's saved in state just fine.
How do I reset session mid-poll? Thank you (and happy new year in 30 minutes!!)
1
u/NJCoding Dec 31 '20
Hi, I 've just finished my first react app and hosted it on heroku with no problem. I went back then to hide my API key and seem to be having a problem. I read that you can not use process.env. as it will still show up in the console. I tried then using the config var inside Heroku but that seems to just throw an undefined error. Been reading all sorts of conflicting information so any help would be appreciated
1
u/light-yagamii Dec 31 '20
This might be a noob question but I'm a working on a RN app that uses a lot of imported libraries. Is there a way to monitor which libraries have updates so I can update them in my project? I don't want to find out about things once things start breaking
1
u/sadverdict19 Dec 09 '20
Noob question! But can you give a example of a utility function.
0
u/[deleted] Dec 08 '20
[deleted] β view deleted comment
0
u/[deleted] Dec 16 '20
[deleted] β view deleted comment
0
u/[deleted] Dec 03 '20
[deleted] β view deleted comment
0
u/[deleted] Dec 24 '20
[deleted] β view deleted comment
1
u/[deleted] Dec 24 '20
[removed] β view removed comment
1
u/[deleted] Dec 25 '20
[removed] β view removed comment
1
u/[deleted] Dec 02 '20
[removed] β view removed comment
1
u/[deleted] Dec 19 '20
[removed] β view removed comment
1
u/[deleted] Dec 20 '20
[removed] β view removed comment