I’m building my JavaScript calculator locally in React and unfortunately, I’m unable to get my display to show up. I’m not sure if the problem is with my CSS or with another portion of my code.
Also, I have several components that appear to be defined but unused within App.js and I’m not sure why this is given that I’ve imported them into the App.js file. At this point, I’m a little confused as to what is going wrong and a push in the right direction would be very beneficial.
Any help is appreciated, thanks.
Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36.
Imo the problem is that you have not decided on your app structure/plan, namely whether you’re going to use components, separate css files and other React Feng Shui or put it in a single component. Eg as I recall you got Button.js, and the whole(?) keyset manually written.It can be confusing, and you can actually do it (mix) anyways.
If you’re new to react and want to finish the project asap, html-like approach (single component/two components) would be easier, and it won’t be DRY at all.
If you want to practice React things, go with components or mix things up, look out for duplicate parts. React docs encourage empirical way
I have implemented my components and incorporated my CSS in a better fashion. However, I only have limited functionality with my calculator and my calculator is now passing fewer tests. This seems to be in part because I need to pass id through my Button component, for example, I’m currently passing id in the following manner:
<div className='row'>
<Button id = 'one' handleClick={this.addToInput}>1</Button>
<Button id = 'two' handleClick={this.addToInput}>2</Button>
<Button id = 'three' handleClick={this.addToInput}>3</Button>
<Button id ='add' data-action='add' handleClick={this.add}>+</Button>
</div>
But the Button component itself does not pass an id:
Please create a repo with the code as you have it locally (including the correct file structure).
Also, you have committed the node_modules folder. You need to add a .gitignore file and exclude the folder.
You have this.state.output in the display but there is no such property on the state object. The display is off to the left side because the container is set to be a flexbox container.
I have a hard time believing that is your local file structure. Where are the src and public folders, where is the components folder? If I just clone and run your project as it is in the repo now I will get errors.
Can you give me an idea of what passing id via props by mapping through my Button component might look like? Do I need to create a separate ID file and then create the id property within my button component? Also, you have <Button/>in.map() did you mean <Button/>id.map()?
Not really sure why you want to pass anything down to the Button component, I would expect that to be stateless and not necessarily need props either.
It might be an array of objects. You would map the array and inside each object would be an id, etc. Then the map callback function will have access to all the properties of the object and can put them on properties on the component.
I would still really appreciate it if you created a repo with your current code as it is locally. Any time you update your code push the changes so we can see the current code and run it locally.