How use it with redux?
See original GitHub issueI have a reducer that updates my “badge” in application design so i have this
import PushNotification from 'react-native-push-notification'
class Main extends Component{
construct(){}
PushNotification.configure({
onRegister: function(token) {
AsyncStorage.getItem('deviceToken',(err,localToken) => {
if(localToken === null){
fetch("myreques",{
method : 'POST'
}).then( response => response.json())
.then( posts => {
AsyncStorage.setItem('deviceToken', token.token);
})
}
})
},
onNotification: function(notification) {
AsyncStorage.getItem('pendingNotifications',(err,data) => {
if(null != data){
data = JSON.parse(data)
data.push({
id : parseInt(notification.id),
viewed : false
})
AsyncStorage.setItem('pendingNotifications',JSON.stringify(data))
}else{
let data = [{
id : notification.id,
viewed : false
}]
AsyncStorage.setItem('pendingNotifications',JSON.stringify(data))
}
//this._updateBagde() <-- this line make app crashes
if(Platform.OS === 'ios'){
PushNotification.setApplicationIconBadgeNumber(parseInt(notification.badge))
}
})
this._updateBagde();
},
// ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
senderID: "MINE",
permissions: {
alert: true,
badge: true,
sound: true
},
popInitialNotification: true,
requestPermissions: true,
});
PushNotification.requestPermissions("MINE");
this._updateBagde()
}
_updateBagde(){
AsyncStorage.getItem('pendingNotifications',(err,notViewed) => {
if(notViewed != null){
//traer las que no han sido vistas
let parsedNotifications = JSON.parse(notViewed)
let filtered = parsedNotifications.filter((item) => {
if(!item.viewed){
return item
}
})
if(Platform.OS === 'ios'){
PushNotification.setApplicationIconBadgeNumber(parseInt(filtered.length))
}
//console.log(filtered,'badge')
this.props.updateBadge(filtered.length)
}
})
}
}
Is this error appearing because redux is an internal javascript structure and “PushNotification.configure” is on a native level?
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:8
Top Results From Across the Web
Getting Started with Redux
The recommended way to start new apps with React and Redux is by using the official Redux+JS template or Redux+TS template for Create...
Read more >How to use Redux in ReactJS with real-life examples
How to use Redux in ReactJS with real-life examples · import { Provider } from "react-redux"; import configureStore from "store"; · ReactDOM.
Read more >Understanding Redux: A tutorial with examples
Simply put, Redux is used to maintain and update data across your applications for multiple components to share, all while remaining independent ...
Read more >How to Use Redux With React: A Step By Step Guide - Medium
In Redux, there is one source of truth: the store · It's not specific to React. You can use it with other frameworks...
Read more >React With Redux Tutorial: Learn the Basics [Updated]
Redux is a predictable state container for JavaScript applications. It helps you write apps that behave consistently, run in different ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oh, I just saw your problem. The onNotification callback you gave is a
function
. Thus, thethis
keyword refers to another object, not your component. In order to solve it, you can declare the onNotification callback as a lambda, like this:onNotification: () => { // your logic here }
USING REDUX WITH NOTIFICATION HANDLER
–>App.js
–>Notificationhandler.js