Skip to content

Commit

Permalink
Update incorrect Hello Remirror docs (#684)
Browse files Browse the repository at this point in the history
- Remove TS specific code
- Ensure labels are returned for mention logic
- Ensure all React methods are imported
- Rename  ```onChange``` to ```onMentionChange```
- Remove ```console.log```
- Rename "junk" to "example"
  • Loading branch information
Bertg committed Sep 15, 2020
1 parent 14e4869 commit a895e62
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions docs/guide/hello-remirror.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ First make sure you've followed the instructions in the [installation guide](/do
Then you'll need to import the relevant code.

```tsx
import React, { useState } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import { SocialEditor } from 'remirror/react/social';
```

This import gives you access to the social editor. Now let's wire it up with some junk data. In reality you'd be fetching this data from an API.
This import gives you access to the social editor. Now let's wire it up with some example data. In reality you'd be fetching this data from an API.

```tsx
import { TagData, UserData } from 'remirror/react/social';

const exampleUsers: UserData[] = [
const exampleUsers: [] = [
{
avatarUrl: 'https://api.adorable.io/avatars/100/tolu@adorable.io.png',
displayName: 'Tolu',
Expand Down Expand Up @@ -72,27 +70,25 @@ Now that the data is available let's use it.
function MyEditor() {
const [mention, setMention] = useState(null);

const onChange = useCallback((parameter) => {
const onMentionChange = useCallback((parameter) => {
setMention(parameter);
}, []);

console.log(mention);

const onExit = useCallback(({ query }, command) => {
command({ href: `/${query.full}` });
}, []);

const items = useMemo(() => {
if (mention && mention.name === 'at' && mention.query) {
return exampleUsers.filter((user) =>
user.username.toLowerCase().includes(mention.query.toLowerCase()),
);
return exampleUsers
.filter((user) => user.username.toLowerCase().includes(mention.query.toLowerCase()))
.map((user) => ({ ...user, label: user.displayName }));
}

if (mention && mention.name === 'tag' && mention.query) {
return exampleTags.filter((tag) =>
tag.tag.toLowerCase().includes(mention.query.toLowerCase()),
);
return exampleTags
.filter((tag) => tag.tag.toLowerCase().includes(mention.query.toLowerCase()))
.map((tag) => ({ ...tag, label: tag.tag }));
}

return [];
Expand All @@ -103,7 +99,7 @@ function MyEditor() {
placeholder='Start typing here'
autoFocus={false}
items={items}
onMentionChange={onChange}
onMentionChange={onMentionChange}
onExit={onExit}
/>
);
Expand Down

1 comment on commit a895e62

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉 Published on https://remirror.io as production
🚀 Deployed on https://5f6077f57d3553a21bd2adbf--remirror.netlify.app

Please sign in to comment.