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

using react-mentions with mongoDB #724

Open
mohqaz opened this issue Dec 25, 2023 · 0 comments
Open

using react-mentions with mongoDB #724

mohqaz opened this issue Dec 25, 2023 · 0 comments

Comments

@mohqaz
Copy link

mohqaz commented Dec 25, 2023

i installed react-mentions I did not discover how to use it, and all I found was an explanation of how to use it with data stored in the same project, (fake data)

And I want to know how to use it with real data that is fetched from a database from MongoDB

It is assumed that as soon as I type @, the system reviews username suggestions, or when I type a letter after it, it suggests usernames that starts with this letter.

but when i type @ nothing happened

Note: I am trying to call the data in Mentions component and then I try to call its input in another component and use it

and this is the code I tried:

Mentions.jsx

const Mentions = () => {
    const [value, setValue] = useState("");
    console.log("Value: ", value);

const fetchUsers = async (username, callback) => {
    if (!username) {
        return;
    }
    const users = await fetch(`http://localhost:5000/api/users/users`)
    const filteredUsers = users.filter((user) => 
    user.includes(username));
    callback(filteredUsers);
}
  return (
    <Box>
        <MentionsInput 
        style={defaultStyle}
        value={value}
        onChange={(e) => setValue(e.target.value)}
        placeholder={"Mention people using '@'"}
        allySuggestionsListLabel={"Suggested mentions"}
        >
            <Mention style={defaultMentionStyle} data={fetchUsers}/>
        </MentionsInput>
    </Box>
  )
}

This is the textarea that I'm trying to make it use the function I wrote in Mentions Component
The textarea exists in another component

CreatePost.jsx

               <Textarea
                placeholder= {`${user.username} say something...`}
                onChange={handleTextChange}
                value={postText}
                />

Observed behaviour:

Workaround:

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

No branches or pull requests

1 participant