Skip to content

Instantly share code, notes, and snippets.

@wedwin53
Created January 21, 2021 23:39
Show Gist options
  • Save wedwin53/7c2977f537df8a67fc5c911c8deba6fa to your computer and use it in GitHub Desktop.
Save wedwin53/7c2977f537df8a67fc5c911c8deba6fa to your computer and use it in GitHub Desktop.
detect enter on a react input component
import React, { useState } from "react";
import "./styles.css";
import WeekPlan from "./WeekPlan";
import dateFns from 'date-fns'
export default function App() {
const [block, setBlock] = useState([]);
const handleBlock = (e) => {
if (e.key === 'Enter') {
console.log('do validate');
console.log("value", e.target.value)
console.log(e.target.value.split('to'))
const bloque1 = new Object()
const entry = e.target.value.split('to');
bloque1.weekDay = 1
bloque1.from = entry[0]
bloque1.to = entry[1]
console.log(bloque1)
}
};
return (
<div className="App">
<h1>Planner</h1>
<div className="text-center">
<input onKeyDown={handleBlock} type="text" />
<button className="btn btn-primary">Test</button>
</div>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment