<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
<script type="text/babel">
const { useRef } = React;
// Sample data with datetime strings and additional properties
{ id: 1, datetime: '2023-08-18 08:00:00', name: 'Andrew', location: 'London' },
{ id: 2, datetime: '2023-08-18 07:30:00', name: 'Smith', location: 'New york' },
{ id: 3, datetime: '2023-08-18 09:15:00', name: 'Emma', location: 'Los Angeles' },
{ id: 4, datetime: '2023-08-18 10:45:00', name: 'John', location: 'San Francisco' },
{ id: 5, datetime: '2023-08-18 11:30:00', name: 'Sophia', location: 'Chicago' },
{ id: 6, datetime: '2023-08-18 12:20:00', name: 'Michael', location: 'Miami' },
{ id: 7, datetime: '2023-08-18 14:00:00', name: 'Olivia', location: 'Toronto' },
{ id: 8, datetime: '2023-08-18 15:45:00', name: 'William', location: 'Seattle' },
{ id: 9, datetime: '2023-08-18 16:30:00', name: 'Ava', location: 'Houston' },
{ id: 10, datetime: '2023-08-18 17:15:00', name: 'James', location: 'Boston' }
// Define your custom comparator function to sort by datetime
function compareDates(a, b) {
const dateA = new Date(a.datetime);
const dateB = new Date(b.datetime);
// Sort the array using the comparator function
<div className='container '>
<h3>React Js Sorted Data by Datetime</h3>
<strong>Name:</strong> {item.name}<br />
<strong>Datetime:</strong> {item.datetime}<br />
<strong>Location:</strong> {item.location}
ReactDOM.render(<App />, document.getElementById('app'));
font-family: Arial, sans-serif;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
background-color: #f5f5f5;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
.container li strong::after {
.container li strong+br {
.container li:last-child {