Skip to content

Instantly share code, notes, and snippets.

@bnayae
Created January 12, 2021 17:49
Show Gist options
  • Save bnayae/6ba332f3553da1caf6cf1aee0d20e036 to your computer and use it in GitHub Desktop.
Save bnayae/6ba332f3553da1caf6cf1aee0d20e036 to your computer and use it in GitHub Desktop.
import React from 'react';
import { useRecoilState } from 'recoil';
import { stateComment, stateStars } from '../../../states';
import { StarsPicker } from '../../ui-units';
export const Details = () => {
const { id, journey } = useRoutingInfo(); // parse query string
const key: IRecoilId = { id, journey };
// best practice (won't cause rendering of the entire component)
const starState = stateStars(key);
// bad practice (will cause rendering of the entire component)
const [comment, setComment] = useRecoilState(stateComment(key));
return (
<div>
<StarsPicker className="raring" state={starState} />
<input
className="comment-input"
type="text"
value={comment}
onChange={(e) => setComment(e.target.value)}
/>
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment