【发布时间】:2021-08-19 11:04:30
【问题描述】:
我目前正在做一个项目,我应该记录用户的声音,然后将其发送到服务器。这个项目是在 ReactJS 和 Redux 中完成的。我可以正确录制声音,但是当我发送这个 blob 以更新商店时,它需要空对象。
我的记录器组件
const RecorderC = () => {
const dispatch = useDispatch();
const handleStop = (audioData) => {
console.log(audioData);
dispatch(sendAudioData(audioData));
};
return (
<div>
<AudioReactRecorder
state={isRecording}
onStop={(audioData) => handleStop(audioData)}
/>
<div className="btns-box">
<button
className="btn btn-danger"
onClick={() => dispatch(startRecordAction())}
>
Start
</button>
<button
className="btn btn-primary"
onClick={() => dispatch(stopRecordAction())}
>
Stop
</button>
</div>
</div>
);
};
我的记录器操作:
export const sendAudioData = (audioData) => {
return {
type: SEND_AUDIO_DATA,
payload: audioData,
};
};
我的recorderReducer:
const recorderReducer = (state = initialState, action) => {
switch (action.type) {
case SEND_AUDIO_DATA:
return {
...state,
blob: action.payload,
};
default:
return state;
}
};
这些操作运行良好。我的意思是商店更新了初始状态,但我的状态中 blob 的值接收到空 blob。下图就是为了证明这一点。
值得一提的是,根据有效负载的控制台日志记录,除了存储接收到空对象之外,一切都很好。
【问题讨论】:
标签: reactjs redux blob dispatch