Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change examples from class to functional components #5393

Merged
merged 2 commits into from Oct 20, 2022
Merged

Conversation

nderkim
Copy link
Collaborator

@nderkim nderkim commented Oct 19, 2022

This PR updates the examples to use functional components

@changeset-bot
Copy link

changeset-bot bot commented Oct 19, 2022

⚠️ No Changeset found

Latest commit: 4a427ac

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 19, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 4a427ac:

Sandbox Source
react-codesandboxer-example Configuration

@@ -22,24 +18,6 @@ const loadOptions = (
}, 1000);
};

export default class WithCallbacks extends Component<{}, State> {
state: State = { inputValue: '' };
Copy link
Collaborator Author

@nderkim nderkim Oct 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the state logic to simplify the example. I don't think it was necessary for demonstrating how to use the async callbacks api.

console.group('Value Changed');
console.log(newValue);
console.log(`action: ${actionMeta.action}`);
console.groupEnd();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the console logs to simplify the example. I don't think they were necessary for the purpose of this example.

@@ -20,20 +16,10 @@ const promiseOptions = (inputValue: string) =>
}, 1000);
});

export default class WithPromises extends Component<{}, State> {
state: State = { inputValue: '' };
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the state logic from this example because it wasn't necessary for the purpose of this example.

};
render() {
const { value } = this.state;
const displayValue =
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this to simplify the example.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda like it for this example ¯_(ツ)_/¯
value.value.toString() is a bit grim though — maybe const [dateOption, setDateOption] = useState<DateOption | null>(defaultOptions[0] as DateOption) would be better?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Hm. Isn't that what i'm already doing in line 222 (except i've just left it named as value instead of renaming it to dateOption)?

handleInputChange = (newValue: string) => {
const inputValue = newValue.replace(/\W/g, '');
this.setState({ inputValue });
return inputValue;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this because it wasn't being used

readonly isSearchable: boolean;
}
export default () => {
const [isClearable, setIsClearable] = useState(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isClearable and isSearchable should start off as true

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch 👍

isMulti={false}
isOptionSelected={(o, v) => v.some((i) => i.date.isSame(o.date, 'day'))}
maxMenuHeight={380}
onChange={props.onChange}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is spread on the props that are spread in above

Copy link
Collaborator Author

@nderkim nderkim Oct 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how it was in the original example. I'm just gonna leave it the way it was. Personally, i think the props spread should go and the onChange should stay (it's more explicit), but im too scared to delete the props spread in case i break something 😰

onChange={props.onChange}
onInputChange={handleInputChange}
options={options}
value={props.value}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is spread on the props that are spread in above

@nderkim nderkim merged commit 78beb17 into master Oct 20, 2022
@nderkim nderkim deleted the alex/tidy-examples branch October 20, 2022 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants