Skip to content

Commit

Permalink
fix: set a default value for the data prop
Browse files Browse the repository at this point in the history
Otherwise it renders a spinner instead of the empty text.
  • Loading branch information
targos committed Jul 14, 2021
1 parent 910d314 commit 7daf6f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/component/NMRium.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,12 @@ export interface NMRiumData {
}

const defaultPreferences = {};
const defaultData: NMRiumData = {
spectra: [],
};

function NMRium({
data: dataProp,
data: dataProp = defaultData,
mode = NMRiumMode.DEFAULT,
preferences = defaultPreferences,
getSpinner = defaultGetSpinner,
Expand Down
6 changes: 3 additions & 3 deletions src/demo/views/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export default function View(props) {
setData(_d);
});
} else {
setData({});
setData(undefined);
}
}, [baseURL, file, props]);

const changeHadnler = useCallback((logData) => {
const changeHandler = useCallback((logData) => {
setCallbackData((prevLogs) => {
return prevLogs.concat({
datetime: new Date().toLocaleTimeString(),
Expand Down Expand Up @@ -113,7 +113,7 @@ export default function View(props) {
>
<div style={{ display: 'flex', flexDirection: 'row', width: '100%' }}>
<div style={{ width: isCallbackVisible ? '75%' : '100%' }}>
<NMRium data={data} onDataChange={changeHadnler} />
<NMRium data={data} onDataChange={changeHandler} />
</div>
{process.env.NODE_ENV !== 'production' && (
<div
Expand Down

0 comments on commit 7daf6f4

Please sign in to comment.