呼叫对推送通知的反应路线
Call react route to Push Notification
我想用 php Symfony 调用一个反应路线。
首先,我在 React 中创建了一个函数路由,如下所示:
import addNotification from 'react-push-notification';
const Notifications = () => {
return (
addNotification({
title: 'Notification',
subtitle: 'Welcome',
message: 'New message',
native: true
})
)
}
export default Notifications
当我调用这条路由时,这个函数会显示一个通知。
其次,当我尝试通过这条路线访问时,我的通知有效,但我有
一个错误:
Error: Objects are not valid as a React child (found: [object
Promise]). If you meant to render a collection of children, use an
array instead.
我不明白这个错误。你能帮我解决这个问题吗?
第三,是否可以用symfony调用这个react路由?
谢谢
您不能 return 来自组件的对象。
如果要在呈现此组件时启动通知,需要在 useEffect hook
中执行
import React, {useEffect} from 'react'
import addNotification from 'react-push-notification';
const Notifications = () => {
useEffect(() => {
addNotification({
title: 'Notification',
subtitle: 'Welcome',
message: 'New message',
native: true
})
}, [])
return null
}
export default Notifications
我想用 php Symfony 调用一个反应路线。
首先,我在 React 中创建了一个函数路由,如下所示:
import addNotification from 'react-push-notification';
const Notifications = () => {
return (
addNotification({
title: 'Notification',
subtitle: 'Welcome',
message: 'New message',
native: true
})
)
}
export default Notifications
当我调用这条路由时,这个函数会显示一个通知。
其次,当我尝试通过这条路线访问时,我的通知有效,但我有 一个错误:
Error: Objects are not valid as a React child (found: [object
Promise]). If you meant to render a collection of children, use an
array instead.
我不明白这个错误。你能帮我解决这个问题吗?
第三,是否可以用symfony调用这个react路由?
谢谢
您不能 return 来自组件的对象。
如果要在呈现此组件时启动通知,需要在 useEffect hook
中执行import React, {useEffect} from 'react'
import addNotification from 'react-push-notification';
const Notifications = () => {
useEffect(() => {
addNotification({
title: 'Notification',
subtitle: 'Welcome',
message: 'New message',
native: true
})
}, [])
return null
}
export default Notifications