## Install
```
npm install --save appconsent-react-tv-cmp
Import the component and use it as follows:
`jsx
import AppconsentCMP from 'appconsent-react-tv-cmp'
function App() {
const config = {
appKey: 'YOUR_APP_KEY',
}
const useCMP = () => {
window.__tcfapi('init', 2, () => {}, config)
window.__tcfapi('show', 2, () => {}, { lazy: true })
}
return (
)
}
`
#### onReady
Function that will be called when global __tcfapi method is available.
Default value: () => {}.
#### onClose
Function that will be called when CMP is closed by back button. CMP can be closed only if canQuitCMP is set to true.
Default value: () => {}.
#### onPageChange
Function that will be called when a CMP page changes: the first page is opened, user opens new page or goes back to previous page.
Default value: () => {}.
#### canQuitCMP
Boolean that defines if the CMP can be closed by pressing back button in the root view.
Default value: false.
Use the following example to close the CMP when back button is pressed.
`jsx
import AppconsentCMP from 'appconsent-react-tv-cmp'
function App() {
const config = {
appKey: 'YOUR_APP_KEY',
}
const useCMP = () => {
window.__tcfapi('init', 2, () => {}, config)
window.__tcfapi('show', 2, () => {}, { lazy: true, jumpAt: 'privacy' })
}
const onClose = () => {
// your code
}
return (
)
}
`
useCMP hook exposes certain CMP methods. If you need to display the CMP, use the component instead of the hook.
`js
import { useCMP } from 'appconsent-react-tv-cmp'
export function MyComponent() {
const cmp = useCMP()
const main = async () => {
await cmp.init(config)
const shouldUpdate = await cmp.checkForUpdate()
}
useEffect(() => {
main()
}, [])
return <>>
}
``
Find out more on https://sfbx.gitbook.io/appconsent/