<?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 (@pierrecode).</description>
    <link>https://dev.to/pierrecode</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%2F1858646%2Fea238829-69fc-4086-8752-9b85fda08dee.png</url>
      <title>DEV Community: Pierre</title>
      <link>https://dev.to/pierrecode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pierrecode"/>
    <language>en</language>
    <item>
      <title>React and Typescript code issues (page refresh + phone compatibility)</title>
      <dc:creator>Pierre</dc:creator>
      <pubDate>Mon, 29 Jul 2024 21:52:45 +0000</pubDate>
      <link>https://dev.to/pierrecode/react-and-typescript-code-issues-page-refresh-phone-compatibility-276o</link>
      <guid>https://dev.to/pierrecode/react-and-typescript-code-issues-page-refresh-phone-compatibility-276o</guid>
      <description>&lt;p&gt;Good evening,&lt;/p&gt;

&lt;p&gt;I am coding my first website in React and Typescript. My site aims to host and display videos (like YouTube for example).&lt;/p&gt;

&lt;p&gt;I have 2 problems that I can't solve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Some of my pages are homepages and others are page display templates. I use router and useLocation() for communication between the two. The problem is that when a user refreshes the page on my page template, useLocation(); is empty and the user then lands on the 404 error: not found page. I would like at least the refresh to redirect to the associated homepage. Here is the code of my Template page:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from 'react';
import './Grille_video_style.css';
import { useLocation, useNavigate } from 'react-router-dom';
import styled from '@emotion/styled';

//Adaptable web/phone style
const ContainerStyle = styled.div`
  top: 0;
  left: 0;
  position: fixed;
  width: 100%;
  height: 100vh;
  justify-content: center;
  background-color: black;

  //Adaptation for phone
  @media (max-width: 85em) {
    width: 70%;
  }
`;


const Grille_video: React.FC = () =&amp;gt; {
  const location = useLocation();
  const { paths } = location.state as { paths: string[] };
  const [videos, setVideos] = useState(paths);
  const [isMobile, setIsMobile] = useState&amp;lt;boolean&amp;gt;(window.matchMedia('(max-width: 85em)').matches);
  const navigate = useNavigate();

  // Back button press function
  const handleBackClick = () =&amp;gt; {
    document.body.style.overflow = 'auto';
    document.exitFullscreen().catch(err =&amp;gt; console.log(err));
    navigate('/Grille');
  };

  // Detection of whether or not the website is used by phone
  useEffect(() =&amp;gt; {
    const handleResize = () =&amp;gt; {
      setIsMobile(window.matchMedia('(max-width: 85em)').matches);
    };

    window.addEventListener('resize', handleResize);

    return () =&amp;gt; {
      window.removeEventListener('resize', handleResize);
    };
  }, []);

  // Disable scrolling
  document.body.style.overflow = 'hidden';

  return (
    &amp;lt;ContainerStyle&amp;gt;
      &amp;lt;button onClick={handleBackClick} style={styles.backButton}&amp;gt;
        Retour
      &amp;lt;/button&amp;gt;
      {videos.map((src, index) =&amp;gt; (
        &amp;lt;video
          key={index}
          style={styles.videoMain}
          controls={isMobile ? selectedVideoIndex === index : true}
          autoPlay
          loop
          muted
          className="custom-video"
          preload="auto"
        &amp;gt;
          &amp;lt;source src={src} type="video/mp4" /&amp;gt;
          Your browser does not support the video tag.
        &amp;lt;/video&amp;gt;
      ))}
    &amp;lt;/ContainerStyle&amp;gt;
  );
};

const styles: { [key: string]: React.CSSProperties | any } = {
  backButton: {
    position: 'absolute',
    top: '10px',
    left: '10px',
    padding: '10px 20px',
    backgroundColor: '#EA6666',
    color: 'white',
    border: 'none',
    borderRadius: '8px',
    cursor: 'pointer',
    zIndex: 1100,
  },
  videoMain: {
    position: 'absolute',
    width: '100vw', 
    height: 'calc(100vh - 50px)',
    objectFit: 'cover',
    opacity: 1,
    zIndex: 1000,
  },
};

export default Grille_video;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;More complex problem, my website works correctly on Samsung but not on IPhone (same browser), some of my features and displays are blocked… How can I make my website compatible with all types of devices? Are there any resources on the internet that help to know what to integrate to be compatible with X phone model?&lt;/li&gt;
&lt;/ul&gt;

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

</description>
      <category>programming</category>
      <category>react</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
