Skip to content

Instantly share code, notes, and snippets.

@cbdyzj
Created April 10, 2022 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbdyzj/c077af14bc50e6490dac07919d111a47 to your computer and use it in GitHub Desktop.
Save cbdyzj/c077af14bc50e6490dac07919d111a47 to your computer and use it in GitHub Desktop.
NameHash.jsx
import React, { useState } from 'react'
import styled from '@emotion/styled'
import murmur3 from '../../utils/murmurhash3_32.js'
const Container = styled.div`
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
height: 75vh;
font-size: 30px;
& div {
margin: 10px 0;
}
& input {
width: 180px;
margin: 0 10px;
border-width: 0 0 1px 0;
outline: none;
font-size: 30px;
}
`
function getNameHash(name) {
if (!name) {
return 0
}
return murmur3(name, 314) % 100
}
export default function NameHash(props) {
const [name, setName] = useState('')
function onNameChange(ev) {
const value = ev.target.value
setName(value)
}
return (
<Container>
<div>
<span>Name:</span>
<input autoFocus type="text" value={name} onChange={ev => onNameChange(ev)}/>
</div>
<div>
<span>Name Hash: {getNameHash(name)}</span>
</div>
</Container>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment