Skip to content

Instantly share code, notes, and snippets.

@talitaoliveira
Last active July 20, 2020 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talitaoliveira/68d90a815c4e90e4da432ecf56e600b7 to your computer and use it in GitHub Desktop.
Save talitaoliveira/68d90a815c4e90e4da432ecf56e600b7 to your computer and use it in GitHub Desktop.
Share component to render ShareNative (using web share api) or ShareLinks (with the specific links)
import React, { useState, useEffect } from 'react'
import ShareNative from '../ShareNative'
import ShareLinks from '../ShareLinks'
import * as S from './styled';
const hasShareNative = () => {
if (typeof navigator !== `undefined`) {
if (navigator.share) {
console.log('suporta o share navigator')
return true
}
return false
console.log('nao suporta o share navigator')
}
console.log('nao tem navigator')
return false
}
const Share = () => (
<S.ShareWrapper>
<S.ShareDescription>Compartilhe:</S.ShareDescription>
{ hasShareNative() ? <ShareNative/> : <ShareLinks/>}
</S.ShareWrapper>
)
export default Share;
import React from 'react'
import * as S from './styled';
const handleClick = () => {
if (navigator.share) {
navigator.share({
title: 'Talita Oliveira',
text: 'Blog - Talita Oliveira',
url: 'https://blog.talitaoliveira.com.br/',
})
.then(() => console.log('Successful share'))
.catch((error) => console.log('Error sharing', error));
}
}
const ShareNative = () => (
<S.ShareIcon onClick={handleClick}></S.ShareIcon>
)
export default ShareNative;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment