Нельзя использовать деструктурированный проп-редукс - PullRequest
1 голос
/ 12 июня 2019

После перехода с React Native 0.57 на 0.59 я пытаюсь использовать деструктурированное избыточное действие, привязанное к реквизиту в моем коде, но у меня есть ошибка Error: "[myFunctionName]" is read-only.

// Did work in React Native 0.57, but don't in 0.59
const { getMember } = this.props

getMember() 


// Work in 0.59
this.props.getMember()

// Here is the binding
const mapActionsToProps = dispatch => ({
    getMember: bindActionCreators(getMember, dispatch)
    selectMember: bindActionCreators(selectMember, dispatch),
})
// My action (using redux-axios)
export function getMember(memberId) {
    return {
        type: GET_MEMBER,
        payload: {
            request: {
                method: 'GET',
                url: `/members/${memberId}`,
            },
        },
    }
}

Я ожидал, что мой код будет полностью функциональным после перехода на 0.59, но я не понимаю, почему я не могу использовать деструктурированные реквизиты.

Вот полная трассировка стека:

W/ReactNativeJS: Possible Unhandled Promise Rejection (id: 4):
    Error: "getMember" is read-only.
    http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:228834:34
    _callee$@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:228835:18
    tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23070:23
    invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23245:32
    tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23070:23
    invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23146:30
    http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23176:19
    tryCallTwo@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24371:9
    doResolve@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24535:25
    Promise@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24394:14
    callInvokeWithMethodAndArg@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23175:29
    enqueue@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23180:157
    async@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23196:69
    _callee@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:228829:42
    componentDidMount@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:230137:24
    commitLifeCycles@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:18440:45
    commitAllLifeCycles@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:19791:29
    invokeGuardedCallbackImpl@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8537:21
    invokeGuardedCallback@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8628:42
    commitRoot@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:19985:34
    http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:21196:21
    unstable_runWithPriority@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:38492:30
    completeRoot@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:21195:43
    performWorkOnRoot@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:21136:27
    performWork@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:21059:30
    performSyncWork@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:21035:20
    requestWork@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:20933:26
    scheduleWork@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:20806:22
    enqueueSetState@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:13059:23
    setState@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:4502:37
    _onTransitionEnd@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:150233:23
    cb@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:53559:35
    http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:52152:31
    __debouncedOnEnd@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:55159:23
    __debouncedOnEnd@[native code]
    __invokeCallback@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2629:23
    http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2360:34
    __guard@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2533:15
    invokeCallbackAndReturnFlushedQueue@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2359:21
    invokeCallbackAndReturnFlushedQueue@[native code]
2019-06-12 11:34:00.828 7185-7286/com.coobers.frenchfounders W/ReactNativeJS: Possible Unhandled Promise Rejection (id: 5):
    Error: "getMember" is read-only.
    http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:228834:34
    _callee$@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:228835:18
    tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23070:23
    invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23245:32
    tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23070:23
    invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23146:30
    http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23176:19
    tryCallTwo@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24371:9
    doResolve@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24535:25
    Promise@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24394:14
    callInvokeWithMethodAndArg@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23175:29
    enqueue@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23180:157
    async@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23196:69
    _callee@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:228829:42
    componentDidMount@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:230137:24
    commitLifeCycles@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:18440:45
    commitAllLifeCycles@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:19791:29
    invokeGuardedCallbackImpl@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8537:21
    invokeGuardedCallback@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8628:42
    commitRoot@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:19985:34
    http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:21196:21
    unstable_runWithPriority@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:38492:30
    completeRoot@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:21195:43
    performWorkOnRoot@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:21136:27
    performWork@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:21059:30
    performSyncWork@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:21035:20
    batchedUpdates$1@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:21220:28
    batchedUpdates@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:9951:37
    _receiveRootNodeIDEvent@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:10008:23
    receiveTouches@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:10038:34
    __callFunction@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2579:49
    http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2336:31
    __guard@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2533:15
    callFunctionReturnFlushedQueue@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2335:21
    callFunctionReturnFlushedQueue@[native code]

1 Ответ

1 голос
/ 12 июня 2019

Я нашел решение,

import {
    selectMember as _selectMember, 
    getMember as _getMember,
} from '../../../redux/Member/apiActions'

, а затем связал его так:

const mapActionsToProps = dispatch => ({
    getMember: bindActionCreators(_getMember, dispatch)
    selectMember: bindActionCreators(_selectMember, dispatch),
})

Но дело в том, что я не понимаю, почему миграция с RN 0,57 до 0,59 оборваласьэто ... Мне нужно изменить все мои файлы: (

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...