{"size": 1048, "ext": "js", "max_stars_repo_path": "src/components/playerName.js", "max_stars_repo_name": "mplayer78/gatsby_mr_and_mrs", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/playerName.js", "max_issues_repo_name": "mplayer78/gatsby_mr_and_mrs", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/playerName.js", "max_forks_repo_name": "mplayer78/gatsby_mr_and_mrs", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.8181818182, "max_line_length": 77, "alphanum_fraction": 0.5066793893}
import React, { useContext, useState } from "react"
import GameContext from "../stateHandling/gameContext"

const PlayerName = props => {
  const { state, dispatch } = useContext(GameContext)
  const [name, setName] = useState("")
  return (
    <form
      action="POST"
      onSubmit={e => {
        e.preventDefault()
        dispatch({ type: "setPlayerName", player: props.player, name })
      }}
    >
      {/* //todo remove hardcoded names */}
      <h4>{props.player}</h4>
      <label>
        Name:
        <input
          type="text"
          value={name}
          onChange={e => {
            e.preventDefault()
            setName(e.target.value)
          }}
          onBlur={e =>
            dispatch({ type: "setPlayerName", player: props.player, name })
          }
        />
      </label>
      <button
        onClick={() => {
          setName("")
          dispatch({ type: "setPlayerName", player: props.player, name: "" })
        }}
      >
        Clear
      </button>
    </form>
  )
}

export default PlayerName
