mapStateToProps()
دالة. يجب أن تأخذ هذه الدالة state
كوسيطة ، ثم تقوم بإرجاع كائن يقوم بتعيين هذه الحالة إلى أسماء خصائص محددة. ستصبح هذه الخصائص متاحة للمكون الخاص بك عبر props
. نظرًا لأن هذا المثال يحافظ على الحالة الكاملة للتطبيق في صفيف واحد ، فيمكنك تمرير هذه الحالة بأكملها إلى المكون الخاص بك. قم بإنشاء messages
خاصية في الكائن الذي يتم إرجاعه وتعيينه إلى state
. state
يجب أن تكون مجموعة فارغة.
testString: 'assert(Array.isArray(state) && state.length === 0, "The const state
should be an empty array.");'
- text: ''
testString: 'assert(typeof mapStateToProps === "function", "mapStateToProps
should be a function.");'
- text: ''
testString: 'assert(typeof mapStateToProps() === "object", "mapStateToProps
should return an object.");'
- text: ''
testString: 'assert(mapStateToProps(["messages"]).messages.pop() === "messages", "Passing an array as state to mapStateToProps
should return this array assigned to a key of messages
.");'
```