I am trying to design a React layout that does the following:
- Presents user with Calendar and Checkboxes. (Already done)
- User can select date and select options from checkboxes. (Already done)
- User input will write to array the following info (Need to implement) - Date - Options selected for that date
- The ability to revisit (click-on) a date with options and show which boxes have been checked and change inputs. (Need to implement)
Here is my code so far:
import React, { Component } from 'react';
import './App.css';
import 'react-calendar/dist/Calendar.css';
import Calendar from "react-calendar";
import Checkbox from './components/Checkbox'
class App extends Component {
let sympt = [];
function {
if (sympt.includes(date)) {
// check boolean values in sympt to options & change if necessary
}
// append sympt to add new record
};
render() {
return (
<div>
<Checkbox />
<Calendar />
</div>
);
}
}
export default App;
checkbox.js
class Checkbox extends Component {
constructor() {
super();
this.state = {
categories: [
{id: 1, value: "Symptom 1"},
{id: 2, value: "Symptom 2"},
{id: 3, value: "Symptom 3"},
{id: 4, value: "Symptom 4"}
],
checkedItems: new Map()
};
this.handleChange = this.handleChange.bind(this);
}
handleChange(event) {
var isChecked = event.target.checked;
var item = event.target.value;
this.setState(prevState => ({ checkedItems: prevState.checkedItems.set(item, isChecked) }));
}
render() {
return (
<div>
<h1>Add Notes to Calendar</h1>
<form onSubmit={this.handleSubmit}>
{
this.state.categories.map(item => (
<li>
<label>
<input
type="checkbox"
value={item.id}
onChange={this.handleChange}
/> {item.value}
</label>
</li>
))
}
</form>
</div>
);
}
}
export default Checkbox;
Calendar is using the react-calendar
Here is what is being presented:

What I don't understand how to do are the following:
- Write data to the array in a standardized format. I only want to write to an array once an option is selected, not just when a date is selected.
- Check the array to see if a date already has options attached and "re-check" those boxes.
- Change existing data within the array.
onChangeprop that I think will be useful.