Skip to content

Instantly share code, notes, and snippets.

@PaulieScanlon
Created October 10, 2022 08:13
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 PaulieScanlon/5fd5953371102ae37e34812b96617717 to your computer and use it in GitHub Desktop.
Save PaulieScanlon/5fd5953371102ae37e34812b96617717 to your computer and use it in GitHub Desktop.
Adding the Interface
import React, { Fragment, useState } from 'react';
...
const Page = () => {
...
- return
+ return (
+ <section>
+ <div>
+ {!hasVoted ? (
+ <Fragment>
+ {config.map((item, index) => {
+ const { name, id } = item;
+ return (
+ <button key={index} onClick={() => handleClick(id)} disabled={isSubmitting || error}>
+ <span>{name}</span>
+ </button>
+ );
+ })}
+ </Fragment>
+ ) : (
+ <Fragment>
+ {results.data.map((result, index) => {
+ const { percent, isMax } = result;
+ const name = config[index].name;
+ return (
+ <div key={index}>
+ <span
+ style={{
+ backgroundColor: isMax ? 'blue' : 'gray',
+ width: `${percent}%`
+ }}
+ />
+ <span>{name}</span>
+ <span>{`${percent}%`}</span>
+ </div>
+ );
+ })}
+ </Fragment>
+ )}
+ </div>
+ {hasVoted ? <p>{`${results.total} votes`}</p> : null}
+ {error ? <p>{error.message}</p> : null}
+ </section>
+ );
};
export default Page;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment