# useName

Służy do pobierania nazw wybranych utworów lub modlitw na podstawie identyfikatora playlisty.

{% code title="useName.js" lineNumbers="true" %}

```javascript
import { useContext } from 'react';
import { PlaylistContext } from 'providers/PlaylistProvider';
import { ContentContext } from 'providers/ContentProvider';

const useNames = () => {
  const { playlists } = useContext(PlaylistContext);
  const { content } = useContext(ContentContext);

  const getNames = (id) => {
    let playlist = playlists.find((elem) => elem.id === id);
    let names = [];

    playlist.playlist.forEach((id) => {
      if (id.slice(0, 4) === 'song')
        names.push(content.songs.find((elem) => elem.id === Number(id.slice(6))).name);
      else if (id.slice(0, 4) === 'pray')
        names.push(content.prayers.find((elem) => elem.id === Number(id.slice(6))).name);
    });
    return names;
  };

  return {
    getNames,
  };
};

export default useNames;
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://optimal-it.gitbook.io/parafiaskoczow/dla-programistow/playlist-maker/hooks/usename.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
