I am a newbie to React and kinda JS. I've scoured this website/internet for an answer and can't find what I'm looking for. I have an array with some defined names to start. I'd like for the user to be able to input their own suggestions and add them to the array. Below is my code so far. The random name caller works just fine, but the input is what's really throwing me. It keeps saying addNewName and saveInput are defined/assigned a value but never used, and that this.state is undefined. Appreciate any help, thank you!
import "./styles.css";
import React, { useState } from "react";
import ReactDOM from "react-dom";
export default function App() {
const names = [
{nameCat: "Gibbis"},
{nameCat: "Janet"},
{nameCat: "Big Boy"},
{nameCat: "Martin"},
{nameCat: "Raccoon Baby"},
{nameCat: "Bartholo-MEW"},
];
const [activeCat, setActiveCat] = useState(0);
const randomNames = e => {
const len = names.length;
setActiveCat(Math.floor(Math.random() * len));
};
function saveInput (e) {
names(e.target.value);
}
const addNewName = (e) => {
let { nameCat, input } = this.state;
names.push(input);
setActiveCat({nameCat: nameCat});
};
return (
<div class="container">
<h1 class="gradient-text">let's name that cat!</h1>
<h4>your cat's name is: <span class="catName">{names[activeCat].nameCat}</span></h4>
<button onClick={randomNames}>new name!</button>
<br/>
<br/>
<input
type="text"
onChange={this.addNewName}
/>
<br/>
<br/>
<button onChange={(this.saveInput)}>add new name</button>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);