Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions example/src/components/Docs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState, type SubmitEventHandler } from 'react'
import { useRef, type SubmitEventHandler } from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import GitHubButton from 'react-github-btn'
import { GitHubCalendar, type Props } from 'react-github-calendar'
Expand Down Expand Up @@ -73,14 +73,12 @@ const propsList: Array<[string, DocgenProp]> = [
const Docs = () => {
const [searchParams, setSearchParams] = useSearchParams()
const username = searchParams.get('user') ?? defaultUsername
const [input, setInput] = useState(username)

useEffect(() => {
setInput(username)
}, [username])
const inputRef = useRef<HTMLInputElement>(null)

const onUsernameSubmit: SubmitEventHandler = event => {
event.preventDefault()
const input = inputRef.current?.value.trim().toLowerCase()

if (input && input !== username) {
setSearchParams({ user: input })
}
Expand All @@ -95,12 +93,11 @@ const Docs = () => {
<div>A React component to display a GitHub contributions calendar </div>
<form onSubmit={onUsernameSubmit}>
<input
ref={inputRef}
key={username} // recreate on changes
type="text"
placeholder="Enter your GitHub username"
value={input}
onChange={event => {
setInput(event.target.value.trim().toLowerCase())
}}
defaultValue={username}
autoComplete="on"
required
/>
Expand Down
Loading