Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在组件A中使用redux存储图像状态,并在react native中提取组件B_Javascript_Reactjs_React Native_Redux_React Redux - Fatal编程技术网

Javascript 在组件A中使用redux存储图像状态,并在react native中提取组件B

Javascript 在组件A中使用redux存储图像状态,并在react native中提取组件B,javascript,reactjs,react-native,redux,react-redux,Javascript,Reactjs,React Native,Redux,React Redux,我正在使用世博相机,我正在尝试存储拍摄的图像,并将其作为个人资料图片传递到另一个屏幕上。然而,我似乎无法理解。我对redux基本上是新手,我不太确定我是否做对了。请检查我下面的代码 ImageReducer.js import { ADD_IMAGE } from '../actions/types'; const initialState = { latestImage: null, }; const ImageReducer = (state = initialS

我正在使用世博相机,我正在尝试存储拍摄的图像,并将其作为个人资料图片传递到另一个屏幕上。然而,我似乎无法理解。我对redux基本上是新手,我不太确定我是否做对了。请检查我下面的代码

ImageReducer.js

  import { ADD_IMAGE } from '../actions/types';

  const initialState = {
    latestImage: null,
  };

  const ImageReducer = (state = initialState, action) => {
    switch (action.type) {
      case ADD_IMAGE:
        return {
          ...state,
          url: action.url
        };

      default:
        return state;

    }
  };

  export default ImageReducer;
ProfileImageAction.js

  import { ADD_IMAGE} from './types';

  export const ProfileImageAction = (url) => {
    return {
      type: ADD_IMAGE,
      url
    };
  };
reducers/index.js

    import { combineReducers } from 'redux';
    import ImageReducerfrom './ImageReducer';

    export default combineReducers({
      image: ImageReducer
    });
TakePicture.js

    import { Camera, Permissions } from 'expo';
    import { connect } from 'react-redux';
    import { ProfileImageAction } from '../../../../.././src/actions';

    class TakePicture extends Component {

      constructor(props) {
        super(props);
        this.state = {
          hasCameraPermission: null,
          type: Camera.Constants.Type.back,
          latestImage: null
        };
      }


      takePicture = async (latestImage) => {
        if (this.camera) {
          console.log('');

          const photo = await this.camera.takePictureAsync({ base64: true });

          this.setState({
            foo: Math.random()
          });

          const formData = new FormData();
          formData.append('image', photo.base64);
          formData.append('type', 'base64');

          this.setState({
            latestImage: photo.uri,
            isCameraVisible: false
          });
      }

      this.props.dispatch(ProfileImageAction (latestImage));
      };

    render() {
      return (
        .....
      );
    } }

    const mapStateToProps = ({ state }) => {
      return {
        image: state
      };
    };


    export default connect(mapStateToProps, { ProfileImageAction })(TakePicture);
ImageContainer.js

     import { connect } from 'react-redux';

    class ImageContainer extends Component {

      render() {
        console.log(this.props);
        return (

                      <View style={styles.imageContainer}>
                        <Image
                          style={styles.imageStyle}
                          source={this.props.profilePicture}
                        />
                      </View>
                  )

                }

              }
    function mapStateToProps(state) {
      return {
        profilePicture: state.profilePicture
      };
    }

    export default connect(mapStateToProps, null)(ImageContainer);
从'react redux'导入{connect};
类ImageContainer扩展组件{
render(){
console.log(this.props);
返回(
)
}
}
函数MapStateTops(状态){
返回{
profilePicture:state.profilePicture
};
}
导出默认连接(MapStateTops,null)(ImageContainer);

“存储拍摄的图像并将其作为个人资料图片传递到另一个屏幕”我不清楚您想要实现什么,可能对其他读者也是如此。您可以尝试更详细地描述您的问题吗?我正在使用expo.camera拍摄照片,我想将拍摄的图像传递到另一个类组件,从takePicture.js到imagecontainer.js您在这里有一个错误source={{uri:this.props.profilePicture}我收到了这个错误“错误:“NurfFurSurvieEng即t”中的C++异常”存储所拍摄的图像并将其传递到另一个屏幕作为配置文件图片。“我不清楚你想要实现什么,可能对其他读者也是如此。您可以尝试更详细地描述您的问题吗?我正在使用expo.camera拍摄照片,我想将拍摄的图像传递到另一个类组件,从takePicture.js到imagecontainer.js您在这里有一个错误source={{uri:this.props.profilePicture}我收到了这个错误“错误:‘nFrutFurQueReCurnEt’中的C++异常”