<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Pierre</title>
    <description>The latest articles on DEV Community by Pierre (@pierrot10).</description>
    <link>https://dev.to/pierrot10</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2517019%2Fca003fd9-7d44-4249-ab35-ce1248e668e5.png</url>
      <title>DEV Community: Pierre</title>
      <link>https://dev.to/pierrot10</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pierrot10"/>
    <language>en</language>
    <item>
      <title>How to setup React Native / expo push notification according to different types of notification</title>
      <dc:creator>Pierre</dc:creator>
      <pubDate>Thu, 05 Mar 2026 21:28:23 +0000</pubDate>
      <link>https://dev.to/pierrot10/how-to-setup-expo-push-notification-according-to-different-types-of-notification-12ol</link>
      <guid>https://dev.to/pierrot10/how-to-setup-expo-push-notification-according-to-different-types-of-notification-12ol</guid>
      <description>&lt;p&gt;Hi, I am actually desperate.&lt;br&gt;
I need to setup push notification on my IOS/Android app, I buold with React Native / Expo.&lt;/p&gt;

&lt;p&gt;I could setup a simple push notification follwing &lt;a href="https://docs.expo.dev/versions/latest/sdk/notifications/" rel="noopener noreferrer"&gt;this&lt;/a&gt; and &lt;a href="https://medium.com/@nnaemekaonyeji27/react-native-push-notifications-made-simple-ios-android-0d5995f202ab" rel="noopener noreferrer"&gt;this&lt;/a&gt; but my big problem is the following:&lt;/p&gt;

&lt;p&gt;I have several sensors into several field. A fermer have installed the App on his/her smartphone and they can monitor the fields.&lt;/p&gt;

&lt;p&gt;The farmers need to be alarmed with a push notification, when a sensor measures a measure under a threshold value. A farmer can own several fields (let's say 6 fields)&lt;/p&gt;

&lt;p&gt;I want that farmer can active or not a field to be monitor and to be alarmed for the active fields.&lt;/p&gt;

&lt;p&gt;For example, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if he do not active a field, he should never receive a push notification, excepted for the general notification (let's say the type "general"&lt;/li&gt;
&lt;li&gt;if he active the field 2 and 4 and 5, he should reveive only push notification matching to the sensors on field 2,4 and 5.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On my PHP scrypt (on my remote server) I can send push notification, but the script should send a push notification to the IOS/Addroid which are registered for the active field. (2,4 and 5 according to my above example)&lt;/p&gt;

&lt;p&gt;I spent days and weeks to search how I could registered the App of a smartphone according to my needs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step 1: the farmer open the App. The app is registred for push notification&lt;/li&gt;
&lt;li&gt;Step 2: The farmer go the the setting view&lt;/li&gt;
&lt;li&gt;Step 3: The farmer chose and select the fields he want to monitor&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How Expo notification can save the selected field as channel or categories?&lt;br&gt;
And how can my php script know on which devise it has to send the push notification&lt;/p&gt;

&lt;p&gt;Other scenarios:&lt;br&gt;
Smartphone 1 saved the fields 1, 2 ,3&lt;br&gt;
Samrtphone 2 saved the field 2,4,6&lt;br&gt;
Smartphone 3 saved the field 3&lt;br&gt;
Smartphone 4 saved the field 4,5&lt;br&gt;
Smartphone 5 saved the field 6&lt;/p&gt;

&lt;p&gt;On the morning, a station on field 6 run into alarm. How can I setup Expo to send a push notification to the Samrtphone 2 and 5 only&lt;/p&gt;

&lt;p&gt;On the after noon, the stations on fields 2 and 4 run into alarm. How can I setup Expo to send a notification to the Smartphone 1,2 and 4 only?&lt;/p&gt;

&lt;p&gt;I want to inform an update, how can I send a push notification to all Samrtphone&lt;/p&gt;

&lt;p&gt;I kindly thank for your help, because I am lost :)&lt;/p&gt;

&lt;p&gt;Cheers&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>mobile</category>
      <category>ios</category>
      <category>android</category>
    </item>
    <item>
      <title>is there to use types in different screens</title>
      <dc:creator>Pierre</dc:creator>
      <pubDate>Wed, 31 Dec 2025 22:47:58 +0000</pubDate>
      <link>https://dev.to/pierrot10/is-there-to-use-types-in-different-screens-47aj</link>
      <guid>https://dev.to/pierrot10/is-there-to-use-types-in-different-screens-47aj</guid>
      <description>&lt;p&gt;Hi,&lt;br&gt;
I declare the following type in my screen toto.tsx&lt;/p&gt;

&lt;p&gt;&lt;code&gt;type STA = {&lt;br&gt;
    response: number, &lt;br&gt;
    id: number,&lt;br&gt;
    method: string,&lt;br&gt;
    next: string | null,&lt;br&gt;
    fields: {&lt;br&gt;
        id_field: number,&lt;br&gt;
        field_name: string,&lt;br&gt;
        field_longname: string,&lt;br&gt;
        field_city: string,&lt;br&gt;
        field_lat: number,&lt;br&gt;
        field_lng: number&lt;br&gt;
    }[],&lt;br&gt;
    stations: {&lt;br&gt;
        id_field: number,&lt;br&gt;
        field_name: string,&lt;br&gt;
        id_station: number,&lt;br&gt;
        station_longname: string,&lt;br&gt;
        station_type_awe: string,&lt;br&gt;
        id_station_type: number,&lt;br&gt;
        station_type_name: string,&lt;br&gt;
        station_archive: number,&lt;br&gt;
        lat: number,&lt;br&gt;
        lng: number,&lt;br&gt;
        alt: number,&lt;br&gt;
        measures: {&lt;br&gt;
            datasets: {&lt;br&gt;
                data:{&lt;br&gt;
                    value: number,&lt;br&gt;
                    label: string,&lt;br&gt;
                    date: string,&lt;br&gt;
                    dataPointText: number&lt;br&gt;
                }[],&lt;br&gt;
                label: string,&lt;br&gt;
                showLine:boolean,&lt;br&gt;
                borderColor:string,&lt;br&gt;
                backgroundColor:string,&lt;br&gt;
                pointStyle:string,&lt;br&gt;
                fill:boolean,&lt;br&gt;
                borderWidth:number,&lt;br&gt;
                pointRadius:number,&lt;br&gt;
                type:string,&lt;br&gt;
            },&lt;br&gt;
            labels: {}[],&lt;br&gt;
            unit: string,&lt;br&gt;
            chartContainer: string,&lt;br&gt;
            id_sensor_type: number,&lt;br&gt;
            id_sensor:number,&lt;br&gt;
            sensor_type: string,&lt;br&gt;
            sensor_type_longname: string,&lt;br&gt;
            sensor_type_awe: string,&lt;br&gt;
        }[],&lt;br&gt;
        measures_found: number,&lt;br&gt;
        station_found: number,&lt;br&gt;
        latest_measure: string,&lt;br&gt;
    }[],&lt;br&gt;
    map_center:{&lt;br&gt;
        lat: number,&lt;br&gt;
        lng: number,&lt;br&gt;
    },&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;but I need it for the Screen titi.tsx, as well. I can copy/past it but if I need in a third Screen, it will be not easy to manage it if a change happen.&lt;/p&gt;

&lt;p&gt;How can I create a file for that prupose, that I could import into the needed Screens?&lt;/p&gt;

&lt;p&gt;Should I simply create a file in /constants/? But it be a .ts, a .tsx, a js?&lt;/p&gt;

&lt;p&gt;That would ne great&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>typescript</category>
    </item>
    <item>
      <title>useContext does not update or show the value</title>
      <dc:creator>Pierre</dc:creator>
      <pubDate>Sat, 31 May 2025 11:43:34 +0000</pubDate>
      <link>https://dev.to/pierrot10/setcontext-does-not-update-or-show-the-value-e7c</link>
      <guid>https://dev.to/pierrot10/setcontext-does-not-update-or-show-the-value-e7c</guid>
      <description>&lt;p&gt;I need to save the ID of a field from the settings.tsx view. That value need to be used with other view, like stations.tsx, alarms.tsx, map.tsx.&lt;/p&gt;

&lt;p&gt;If later, I need to watch another field, I can change the field from a drop menu and the new value must be used from the other field. It meens, I should be able to print the select ID filed from the other View, but it does not!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First&lt;/strong&gt; I renamed /hook/fieldContext.ts to /hook/filedProvider.tsx. I needed to add ts*&lt;em&gt;x&lt;/em&gt;* to avoid error message at &lt;code&gt;FieldContext.Provider&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I copied a suggestion as the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { createContext, useState, ReactNode } from 'react';

type FieldContextType = {
  field: string;
  setField: (value: string) =&amp;gt; void;
};

export const FieldContext = createContext&amp;lt;FieldContextType | undefined&amp;gt;(undefined);

export const FieldProvider = ({ children }: { children: ReactNode }) =&amp;gt; {
  const [field, setField] = useState("-1");

  return (&amp;lt;FieldContext.Provider value={{ field, setField }}&amp;gt;
    {children}
  &amp;lt;/FieldContext.Provider&amp;gt;);

};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Q1: I suppose, the above code is not a hook any more because of tsx. Should I move it to constants or components ?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Secondly:&lt;/strong&gt; It has been asked to add &lt;code&gt;&amp;lt;FieldProvider&amp;gt;&amp;lt;/FieldProvider&amp;gt;&lt;/code&gt; at the root of my application, where is the navigation. I am confuse.&lt;/p&gt;

&lt;p&gt;Let me first introduce to my structure to better understand my problem&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app
- (tab)
-- map
--- layout.tsx
--- [id].tsx
-- settings
--- layout.tsx
--- setting.tsx
--- info.tsx
-- stations.tsx
-- index.tsx
-- alarms.tsx
-- layout.tsx (add here)
- layout.tsx (or add here?)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My navigation look like&lt;/p&gt;

&lt;p&gt;&lt;em&gt;app/layout.tsx&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;import { Stack } from "expo-router";&lt;br&gt;
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const queryClient = new QueryClient

export default function Layout() {      
  return (
    &amp;lt;QueryClientProvider client={queryClient}&amp;gt;
      &amp;lt;Stack&amp;gt;
        &amp;lt;Stack.Screen 
          name="(tabs)" 
          options={{ 
            headerShown: false
          }} 
        /&amp;gt;
        &amp;lt;Stack.Screen 
          name="+not-found"
          /*
          options={{
            headerShown: false,
          }} 
          */
        /&amp;gt;
      &amp;lt;/Stack&amp;gt;
    &amp;lt;/QueryClientProvider&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and &lt;em&gt;app/(tab)/layout.tsx&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import FontAwesome from '@expo/vector-icons/FontAwesome6';
import { Tabs} from 'expo-router';
import { StyleSheet } from "react-native";
import { useThemeColors } from '@/hooks/useThemeColors';
import { useNavigation } from '@react-navigation/native';
import { useState } from "react";
import { FieldProvider } from '@/hooks/fieldProvider';


export default function TabLayout() {
  const colors= useThemeColors()
  const navigation = useNavigation();

  const [sortKey, setSortKey] = useState&amp;lt;"id_station" | "station_name"&amp;gt;("id_station")

  return (
    &amp;lt;Tabs screenOptions={{ tabBarActiveTintColor: 'green'}}&amp;gt;
      &amp;lt;Tabs.Screen
        name="index"
        options={{
          headerShown: false,
          title: 'Home',
          headerStyle: {backgroundColor: colors.appHeadBackgroundColor, borderColor:'red'},
          headerTintColor: '#000',
          headerTitleStyle: {
            fontWeight: 'normal',
          },
          tabBarIcon: ({ color }) =&amp;gt; &amp;lt;FontAwesome size={28} name="arrows-to-circle" color={color} /&amp;gt;,  
          tabBarStyle: {
            display:'none',
            backgroundColor: colors.appTabBarBackgroundColor,
            paddingTop:8,
            height:70,
          }
        }}
      /&amp;gt;
      &amp;lt;Tabs.Screen
        name="map"
        options={{
          title: 'Map',
          headerShown: false,
          headerStyle: { backgroundColor: colors.appHeadBackgroundColor},
          headerTintColor: '#000',
          headerTitleStyle: {
            fontWeight: 'normal',
          },
          tabBarIcon: ({ color }) =&amp;gt; &amp;lt;FontAwesome size={28} name="map-location-dot" color={color} /&amp;gt;,
          //headerTitle: props =&amp;gt; &amp;lt;LogoTitle /&amp;gt;,
          tabBarStyle: {
            backgroundColor: colors.appTabBarBackgroundColor,
            //paddingTop:8,
            height:70,
          }
        }}
      /&amp;gt;
      &amp;lt;Tabs.Screen
        name="station"
        options={{
          headerStyle: { 
            backgroundColor: colors.appHeadBackgroundColor
          },
          headerTintColor: '#000',
          headerTitleStyle: {
            fontWeight: 'normal',
          },
          headerShown: false,
          href: null,
          tabBarIcon: ({ color }) =&amp;gt; &amp;lt;FontAwesome size={28} name="chart-line" color={color} /&amp;gt;,
          tabBarStyle: {
            //backgroundColor: colors.appTabBarBackgroundColor,
            //paddingTop:8,
            height:70,
          }
        }}
      /&amp;gt;  
      &amp;lt;Tabs.Screen
        name="alarms"
        options={{
          title: 'Alarmes',
          headerShown: false,
          headerStyle: { backgroundColor: colors.appHeadBackgroundColor},
          headerTintColor: '#000',
          headerTitleStyle: {
            fontWeight: 'normal',
          },
          /*
          headerRight: () =&amp;gt; (
            &amp;lt;Button onPress={() =&amp;gt; router.back()}&amp;gt;Back&amp;lt;/Button&amp;gt;
          ),
          */
          tabBarIcon: ({ color }) =&amp;gt; &amp;lt;FontAwesome size={28} name="bell" color={color} /&amp;gt;,
          //headerTitle: props =&amp;gt; &amp;lt;LogoTitle /&amp;gt;,
          tabBarStyle: {
            //backgroundColor: colors.appTabBarBackgroundColor,
            //paddingTop:8,
            height:70,
            //borderWidth:30,
          }
        }}
      /&amp;gt;
      &amp;lt;Tabs.Screen
        name="stations"
        options={{
          title: 'Stations',
          headerShown: false,
          headerStyle: { backgroundColor: colors.appHeadBackgroundColor},
          headerTintColor: '#000',
          headerTitleStyle: {
            fontWeight: 'normal',
          },
          tabBarIcon: ({ color }) =&amp;gt; &amp;lt;FontAwesome size={28} name="map-pin" color={color} /&amp;gt;,
          tabBarStyle: {
            //backgroundColor: colors.appTabBarBackgroundColor,
            height:70,
          }
        }}
      /&amp;gt;
      &amp;lt;Tabs.Screen
        name="settings"
        options={{
          title: 'Paramètres',
          headerShown: false,
          headerStyle: { backgroundColor: colors.appHeadBackgroundColor },
          headerTintColor: '#000',
          headerTitleStyle: {
            fontWeight: 'normal',
          },
          /*
          headerRight: () =&amp;gt; (
            &amp;lt;Button onPress={() =&amp;gt; router.back()}&amp;gt;Back&amp;lt;/Button&amp;gt;
          ),
          */
          tabBarIcon: ({ color }) =&amp;gt; &amp;lt;FontAwesome size={28} name="gear" color={color} /&amp;gt;,
          //headerTitle: props =&amp;gt; &amp;lt;LogoTitle /&amp;gt;,
          tabBarStyle: {
              backgroundColor: colors.appTabBarBackgroundColor,
              //paddingTop:8,
              height:70,
            }
          }}
        /&amp;gt;
    &amp;lt;/Tabs&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I was not really sure if &lt;code&gt;&amp;lt;FieldProvider&amp;gt;&lt;/code&gt; should go to at app/layout.tsx or at app/(tab)/layout.tsx (I tried both)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; How can I get the value in my view settings.tsx and map.tsx. I tried the following in my view alarms.tsx (it need it as well) as that view is very simple at the moment.&lt;/p&gt;

&lt;p&gt;As &lt;code&gt;&amp;lt;FieldProvider&amp;gt;&lt;/code&gt; is in app/layout.tsx, I tried the following, but the selected field is not printed, &lt;code&gt;{filed}&lt;/code&gt; shows an error&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Image, View } from "react-native";
import { useContext, useEffect, useState } from "react";
import { RootView } from "@/components/RootView";
import { ThemedText } from "@/components/ThemedText";
import { Row } from "@/components/Row";
import css from "@/hooks/styles";
import { useThemeColors } from "@/hooks/useThemeColors";
import AsyncStorage from '@react-native-async-storage/async-storage';
import { imagesHeader } from "@/components/imagesHeader";
import { FieldContext, FieldProvider } from "@/hooks/fieldProvider";

export default function Alarms() {

    const colors = useThemeColors()

    const field = useContext(FieldContext)

    return(
    &amp;lt;RootView&amp;gt;
      &amp;lt;View style={[{backgroundColor: colors.appHeadBackgroundColor }]}&amp;gt;
        &amp;lt;View style={css.jumbotronContainer}&amp;gt;
          &amp;lt;Image
            style={css.jumbotronImage}
            source={imagesHeader.alarms.uri}
          /&amp;gt;       
        &amp;lt;/View&amp;gt;
      &amp;lt;/View&amp;gt;

      &amp;lt;View style={css.container}&amp;gt;
        &amp;lt;Row&amp;gt;
          &amp;lt;ThemedText&amp;gt;Terrain sélectionner: &amp;lt;/ThemedText&amp;gt; 
          &amp;lt;ThemedText&amp;gt;{field}&amp;lt;/ThemedText&amp;gt;
        &amp;lt;/Row&amp;gt;
        &amp;lt;ThemedText style={[css.text,css.paragraphe]}&amp;gt;Aucune station en alarme&amp;lt;/ThemedText&amp;gt;
      &amp;lt;/View&amp;gt;
    &amp;lt;/RootView&amp;gt;
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As I am a novice, I sure I missed some steps, but which one? :)&lt;/p&gt;

&lt;p&gt;Thanks for your help!&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>usecontext</category>
      <category>react</category>
    </item>
    <item>
      <title>How can I integrate Leaflet to React Native</title>
      <dc:creator>Pierre</dc:creator>
      <pubDate>Tue, 03 Dec 2024 11:06:05 +0000</pubDate>
      <link>https://dev.to/pierrot10/how-can-i-integrate-leaflet-to-react-native-2518</link>
      <guid>https://dev.to/pierrot10/how-can-i-integrate-leaflet-to-react-native-2518</guid>
      <description>&lt;p&gt;Hi,&lt;br&gt;
I am very new with React Native. I built a smartphone app with Cordova but I want to migrate to Reat Native. My App use and need &lt;a href="https://leafletjs.com/" rel="noopener noreferrer"&gt;Leaftlet&lt;/a&gt; and &lt;a href="https://www.chartjs.org/" rel="noopener noreferrer"&gt;Chartjs&lt;/a&gt; and I need to find a way to use those feature with my new Reat Native 7.6 and Expo App.&lt;/p&gt;

&lt;p&gt;I investigated one full days trying different npm with React Native Leaflet but it looks like have been done for the 7.3 version or older, or I simply could not implement it due to my lake of practice with React Native.&lt;/p&gt;

&lt;p&gt;I will appreciate if you could share your expertise with Leaftlet for React Native 7.6.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;I found the &lt;a href="https://react-leaflet.js.org/" rel="noopener noreferrer"&gt;React-leaflet&lt;/a&gt; npm. Is it compatible &lt;strong&gt;with React Native&lt;/strong&gt;? or it's only built for React?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Would it possible to "inject" my javascript script, I developed for my &lt;a href="https://bud.eco-sensors.ch/" rel="noopener noreferrer"&gt;web app&lt;/a&gt;. My Idea is to use my Javascript script I developped for my Cordova App (instead of the web app, even if it's very similar) and import is to React Native with some adaptaption. In that case, I would not need a npm.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;My I create a map.js and include the leaflet js library and "duplicate" my cordova javascript script?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Do you have any experience with leaftlet and React Native 7.6?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note: I would like to use OpenStreetMap instead of Google and Apple Map.&lt;/p&gt;

&lt;p&gt;Many thanks for any help and I wish you a nice day&lt;br&gt;
Cheers&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>leaflet</category>
      <category>react</category>
      <category>map</category>
    </item>
  </channel>
</rss>
