Eliminate the useEffect infinite loops in post.js
This commit is contained in:
parent
f0b7fb2763
commit
764efd73ca
|
@ -1,36 +1,13 @@
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import {
|
import {
|
||||||
Image,
|
Image,
|
||||||
|
Text,
|
||||||
View,
|
View,
|
||||||
Dimensions,
|
Dimensions,
|
||||||
TouchableWithoutFeedback
|
TouchableWithoutFeedback
|
||||||
} from "react-native";
|
} from "react-native";
|
||||||
import { activeOrNot } from "src/interface/interactions";
|
import { activeOrNot } from "src/interface/interactions";
|
||||||
|
|
||||||
function invertField (field, state, updater) {
|
|
||||||
// Takes a function (like `setState`) and uses it to invert the given field of `state`
|
|
||||||
let newState = state;
|
|
||||||
newState[field] = !newState[field];
|
|
||||||
updater(newState);
|
|
||||||
}
|
|
||||||
|
|
||||||
// These callbacks will eventually make calls to the instance's API
|
|
||||||
function favouritedCallback(state, updater) {
|
|
||||||
invertField("favourited", state, updater);
|
|
||||||
}
|
|
||||||
|
|
||||||
function commentCallback(state, updater) {
|
|
||||||
invertField("commenting", state, updater);
|
|
||||||
}
|
|
||||||
|
|
||||||
function reblogCallback(state, updater) {
|
|
||||||
invertField("reblogged", state, updater);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bookmarkCallback(state, updater) {
|
|
||||||
invertField("bookmarked", state, updater);
|
|
||||||
}
|
|
||||||
|
|
||||||
const PostActionJsx = (props) => {
|
const PostActionJsx = (props) => {
|
||||||
return (
|
return (
|
||||||
<TouchableWithoutFeedback
|
<TouchableWithoutFeedback
|
||||||
|
@ -77,20 +54,32 @@ const PostActionBarJsx = (props) => {
|
||||||
field = "favourited"
|
field = "favourited"
|
||||||
pack = { icons.heart }
|
pack = { icons.heart }
|
||||||
state = { state }
|
state = { state }
|
||||||
callback = { () => favouritedCallback(state, setState) } />
|
callback = {
|
||||||
|
() => {
|
||||||
|
setState({ ...state, favourited: !state.favourited });
|
||||||
|
}
|
||||||
|
} />
|
||||||
|
|
||||||
<PostActionJsx
|
<PostActionJsx
|
||||||
field = "reblogged"
|
field = "reblogged"
|
||||||
pack = { icons.reblog }
|
pack = { icons.reblog }
|
||||||
state = { state }
|
state = { state }
|
||||||
callback = { () => reblogCallback(state, setState) } />
|
callback = {
|
||||||
|
() => {
|
||||||
|
setState({ ...state, reblogged: !state.reblogged });
|
||||||
|
}
|
||||||
|
} />
|
||||||
|
|
||||||
<PostActionJsx
|
<PostActionJsx
|
||||||
field = "bookmarked"
|
field = "bookmarked"
|
||||||
pack = { icons.bookmark }
|
pack = { icons.bookmark }
|
||||||
last = { true }
|
last = { true }
|
||||||
state = { state }
|
state = { state }
|
||||||
callback = { () => bookmarkCallback(state, setState) } />
|
callback = {
|
||||||
|
() => {
|
||||||
|
setState({ ...state, bookmarked: !state.bookmarked });
|
||||||
|
}
|
||||||
|
} />
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,7 +175,7 @@ export const PostByDataJsx = (props) => {
|
||||||
loaded: true
|
loaded: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
|
@ -224,7 +224,7 @@ export const PostByIdJsx = (props) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
});
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
|
|
Loading…
Reference in New Issue