2 thoughts on “You attempted to set the key ‘social’ with the value

  1. i solve the problem. it’s error when assign object. It can’t set key ‘social’ when you share a second time.
    i fixed it like this:

    import React, { Component } from 'react'
    import {
      Clipboard,
      ToastAndroid,
      AlertIOS,
      Platform
    } from 'react-native'
    import Share, { ShareSheet, Button } from 'react-native-share'
    
    export default class TestShare extends Component {
      constructor (props) {
        super(props)
        this.state = {
          visible: false
        }
      }
    
      componentWillMount () {
        this.setState({ shareOptions: this.props.shareOptions })
      }
    
      onCancel () {
        console.log('CANCEL')
        this.setState({ visible: false })
      }
      onOpen () {
        console.log('OPEN')
        this.setState({ visible: true })
      }
      render () {
        return (
          <ShareSheet visible={this.state.visible} onCancel={this.onCancel.bind(this)}>
            <Button iconSrc={{ uri: TWITTER_ICON }}
              onPress={() => {
                this.onCancel()
                setTimeout(() => {
                  Share.shareSingle({
                    title:this.state.shareOptions.title,
                    message: this.state.shareOptions.message,
                    url: this.state.shareOptions.url,
                    subject: this.state.shareOptions.subject,
                    social: 'twitter'
                  })
                }, 300)
              }}>Twitter</Button>
            <Button iconSrc={{ uri: FACEBOOK_ICON }}
              onPress={() => {
                this.onCancel()
                setTimeout(() => {
                  Share.shareSingle({
                   title:this.state.shareOptions.title,
                    message: this.state.shareOptions.message,
                    url: this.state.shareOptions.url,
                    subject: this.state.shareOptions.subject,
                    social: 'facebook'
                  })
                }, 300)
              }}>Facebook</Button>
            <Button iconSrc={{ uri: WHATSAPP_ICON }}
              onPress={() => {
                this.onCancel()
                setTimeout(() => {
                  Share.shareSingle({
                    title:this.state.shareOptions.title,
                    message: this.state.shareOptions.message,
                    url: this.state.shareOptions.url,
                    subject: this.state.shareOptions.subject,
                    social: 'whatsapp'
                  })
                }, 300)
              }}>Whatsapp</Button>
            <Button iconSrc={{ uri: GOOGLE_PLUS_ICON }}
              onPress={() => {
                this.onCancel()
                setTimeout(() => {
                  Share.shareSingle({
                    title:this.state.shareOptions.title,
                    message: this.state.shareOptions.message,
                    url: this.state.shareOptions.url,
                    subject: this.state.shareOptions.subject,
                    social: 'googleplus'
                  })
                }, 300)
              }}>Google +</Button>
            <Button iconSrc={{ uri: EMAIL_ICON }}
              onPress={() => {
                this.onCancel()
                setTimeout(() => {
                  Share.shareSingle({
                    title:this.state.shareOptions.title,
                    message: this.state.shareOptions.message,
                    url: this.state.shareOptions.url,
                    subject: this.state.shareOptions.subject,
                    social: 'email'
                  })
                }, 300)
              }}>Email</Button>
            <Button
              iconSrc={{ uri: CLIPBOARD_ICON }}
              onPress={() => {
                this.onCancel()
                setTimeout(() => {
                  if (typeof this.props.shareOptions['url'] !== 'undefined') {
                    Clipboard.setString(this.props.shareOptions['url'])
                    if (Platform.OS === 'android') {
                      ToastAndroid.show('Link copiado al portapapeles', ToastAndroid.SHORT)
                    } else if (Platform.OS === 'ios') {
                      AlertIOS.alert('Link copiado al portapapeles')
                    }
                  }
                }, 300)
              }}>Copy Link</Button>
          </ShareSheet>
        )
      }
    }
    
  2. Change
    Share.shareSingle(Object.assign(this.shareOptions, {“social”: type})).catch(err => console.log(err))
    to
    Share.shareSingle(Object.assign({},shareOptions, {
    “social”: “email”
    })).catch(err => console.log(err));
    Props are already frozen in development mode, assign properties of several objects on to a new target object, so we don’t mutate any exist data.

Comments are closed.

3 thoughts on “You attempted to set the key ‘social’ with the value

  1. i solve the problem. it’s error when assign object. It can’t set key ‘social’ when you share a second time.
    i fixed it like this:

    import React, { Component } from 'react'
    import {
      Clipboard,
      ToastAndroid,
      AlertIOS,
      Platform
    } from 'react-native'
    import Share, { ShareSheet, Button } from 'react-native-share'
    
    export default class TestShare extends Component {
      constructor (props) {
        super(props)
        this.state = {
          visible: false
        }
      }
    
      componentWillMount () {
        this.setState({ shareOptions: this.props.shareOptions })
      }
    
      onCancel () {
        console.log('CANCEL')
        this.setState({ visible: false })
      }
      onOpen () {
        console.log('OPEN')
        this.setState({ visible: true })
      }
      render () {
        return (
          <ShareSheet visible={this.state.visible} onCancel={this.onCancel.bind(this)}>
            <Button iconSrc={{ uri: TWITTER_ICON }}
              onPress={() => {
                this.onCancel()
                setTimeout(() => {
                  Share.shareSingle({
                    title:this.state.shareOptions.title,
                    message: this.state.shareOptions.message,
                    url: this.state.shareOptions.url,
                    subject: this.state.shareOptions.subject,
                    social: 'twitter'
                  })
                }, 300)
              }}>Twitter</Button>
            <Button iconSrc={{ uri: FACEBOOK_ICON }}
              onPress={() => {
                this.onCancel()
                setTimeout(() => {
                  Share.shareSingle({
                   title:this.state.shareOptions.title,
                    message: this.state.shareOptions.message,
                    url: this.state.shareOptions.url,
                    subject: this.state.shareOptions.subject,
                    social: 'facebook'
                  })
                }, 300)
              }}>Facebook</Button>
            <Button iconSrc={{ uri: WHATSAPP_ICON }}
              onPress={() => {
                this.onCancel()
                setTimeout(() => {
                  Share.shareSingle({
                    title:this.state.shareOptions.title,
                    message: this.state.shareOptions.message,
                    url: this.state.shareOptions.url,
                    subject: this.state.shareOptions.subject,
                    social: 'whatsapp'
                  })
                }, 300)
              }}>Whatsapp</Button>
            <Button iconSrc={{ uri: GOOGLE_PLUS_ICON }}
              onPress={() => {
                this.onCancel()
                setTimeout(() => {
                  Share.shareSingle({
                    title:this.state.shareOptions.title,
                    message: this.state.shareOptions.message,
                    url: this.state.shareOptions.url,
                    subject: this.state.shareOptions.subject,
                    social: 'googleplus'
                  })
                }, 300)
              }}>Google +</Button>
            <Button iconSrc={{ uri: EMAIL_ICON }}
              onPress={() => {
                this.onCancel()
                setTimeout(() => {
                  Share.shareSingle({
                    title:this.state.shareOptions.title,
                    message: this.state.shareOptions.message,
                    url: this.state.shareOptions.url,
                    subject: this.state.shareOptions.subject,
                    social: 'email'
                  })
                }, 300)
              }}>Email</Button>
            <Button
              iconSrc={{ uri: CLIPBOARD_ICON }}
              onPress={() => {
                this.onCancel()
                setTimeout(() => {
                  if (typeof this.props.shareOptions['url'] !== 'undefined') {
                    Clipboard.setString(this.props.shareOptions['url'])
                    if (Platform.OS === 'android') {
                      ToastAndroid.show('Link copiado al portapapeles', ToastAndroid.SHORT)
                    } else if (Platform.OS === 'ios') {
                      AlertIOS.alert('Link copiado al portapapeles')
                    }
                  }
                }, 300)
              }}>Copy Link</Button>
          </ShareSheet>
        )
      }
    }
    
  2. Change
    Share.shareSingle(Object.assign(this.shareOptions, {“social”: type})).catch(err => console.log(err))
    to
    Share.shareSingle(Object.assign({},shareOptions, {
    “social”: “email”
    })).catch(err => console.log(err));
    Props are already frozen in development mode, assign properties of several objects on to a new target object, so we don’t mutate any exist data.

  3. Pingback: DevSecOps

Comments are closed.