JavaScript Date not passed via props in react js [Now fixed]

  • Thread starter Thread starter shivajikobardan
  • Start date Start date
AI Thread Summary
The discussion centers around a React application that displays subscription information. The main issue identified is a coding error where the date is not formatted correctly for display. The current output does not show the date at the top as intended. The solution proposed is to correct the method call from date.toISOString to date.toISOString(), ensuring the date is properly formatted and displayed first in the output. The application structure includes an App component that imports a Subscription component, which receives subscription data as props for rendering.
shivajikobardan
Messages
637
Reaction score
54
[CODE lang="javascript" title="App.js"]import './App.css';
import Subscription from './components/Subscription';
// import Myroutes from "./Myroutes.js";

function App() {
let subscriptions = [{ id: "1", date: new Date("2021", "3", "23"), title: "Monthly Subscription", amount: "125.60" },
{ id: "2", date: new Date("2020", "06", "28"), title: "Annual Subscription", amount: "1125.60" },
{ id: "1", date: new Date("2021", "09", "05"), title: "Quarterly Subscription", amount: "425.60" }]

return (
<>
<div className='App'>
<Subscription datePassed={subscriptions[0].date.toISOString} titlePassed={subscriptions[0].title} amountPassed={subscriptions[0].amount} />
<Subscription datePassed={subscriptions[1].date.toISOString} titlePassed={subscriptions[1].title} amountPassed={subscriptions[1].amount} />
<Subscription datePassed={subscriptions[2].date.toISOString} titlePassed={subscriptions[2].title} amountPassed={subscriptions[2].amount} />
</div>
</>
)
};

export default App;
[/CODE]

[CODE lang="javascript" title="Subscription.js component"]import React from 'react'
import "./Subscription.css"
function Subscription(props) {
return (
<>
<div>{props.datePassed}</div>
<h2 className="subscription-title">{props.titlePassed}</h2>
<div>{props.amountPassed}</div>
</>)
}

export default Subscription[/CODE]

Currrent Output that I'm getting:
1672147338777.png

Expected Output:

I need date to come at the top.
 
Technology news on Phys.org
FIXED:
date.toISOString should be date.toISOString()
 
  • Like
Likes jedishrfu and .Scott
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
2
Views
1K
Replies
8
Views
2K
Replies
2
Views
2K
Replies
5
Views
2K
Replies
10
Views
3K
Replies
32
Views
2K
Replies
5
Views
2K
Replies
2
Views
1K
Back
Top