目前我正在看这个代码,但无法弄清楚是什么问题.
function fibNumbers() {
return [0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
}
function continiusFib(a) {
var b = fibNumbers(),
c = Math.floor(a),
d = Math.ceil(a);
if (d >= b.length)
return null;
a = Math.pow(a - c, 1.15);
return b[c] + (b[d] - b[c]) * a
}
function drawSpiral(pointA, pointB) {
var b = pointA;
var c = pointB;
ctx.translate(b.x, b.y);
b = Math.sqrt(((c.x - b.x) * (c.x - b.x)) + ((c.y - b.y) * (c.y …Run Code Online (Sandbox Code Playgroud) 我有这些条件:
- 创建点A,B和C.
- 点A到点B将创建一条线.
- 根据A,B和C点的位置创建平行线(参见下图).
- 如果移动A点,线条也会移动,但B点和C点保持在各自的位置.
- 它们可以在任何位置移动.
我想要的是创造这个:
我CRA --template typescript在setupProxy.js文件中使用了这段代码
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function (app) {
app.use(
'/user/try',
createProxyMiddleware({
target: 'http://localhost:8002',
changeOrigin: true,
})
);
};
Run Code Online (Sandbox Code Playgroud)
但问题是setupProxy.js文件被完全忽略导致我的请求失败。
我知道我可以使用"proxy": "http://localhost:8002"inpackage.json但它不接受多个代理。
为了进一步测试,我还创建了一个新的CRA但没有打字稿,突然它可以使用上面相同的代码。
有没有办法setupProxy.js在CRA 打字稿中工作?
我有这个 store/index.ts
export const storeRedux = createStore(
persistReducer(ReduxPersistConfig, rootReducer),
composeEnhancers(applyMiddleware(sagaMiddleware))
);
Run Code Online (Sandbox Code Playgroud)
并使用此实现来访问组件外部的令牌
//api.ts
import axios from 'axios';
import { storeRedux } from 'store';
let token;
const listener = () => {
token = storeRedux.getState().user.token;
};
storeRedux.subscribe(listener);
// console.log(() => getAPI());
export default axios.create({
baseURL: 'http://localhost:5000/api/security',
headers: {
Authorization: `Bearer ${token}`,
},
});
Run Code Online (Sandbox Code Playgroud)
如果我添加一个 setTimeout 来包装,getState()那么一切都会好起来的。
是否有其他解决方案,因为商店已经像本文中那样分开了
例如我有这个字符串
http://www.merriam-webster.com/dictionary/sample
Run Code Online (Sandbox Code Playgroud)
我想要的是只返回merriam-webster.com我打算使用的,.Replace()但我认为这个问题有更好的方法。
我的目的是在内调用一个动作useEffect。
const ShowTodos = (props) =>{
useEffect(()=>{
props.fetchTodos()
},[])
}
const mapStateToProps = (state)=>{
return {
todos:Object.values(state.todos),
currentUserId:state.authenticate.userId
}
}
export default connect(mapStateToProps,{fetchTodos})(ShowTodos)
Run Code Online (Sandbox Code Playgroud)
效果很好,但我收到警告
React Hook useEffect has a missing dependency: 'props'. Either include it or remove the dependency array react-hooks/exhaustive-deps.
Run Code Online (Sandbox Code Playgroud)
但是,如果要props在我的参数中添加第二个参数,useEffects则它将无限运行。
我在这里的第一个解决方法是使用,useRef但它似乎总是会重新渲染,因此再次重新设置useRef,我认为这在优化方面并不好。
const ref = useRef();
ref.current = props;
console.log(ref)
useEffect(()=>{
ref.current.fetchTodos()
},[])
Run Code Online (Sandbox Code Playgroud)
这里还有其他解决方法吗?
我有这个例如:
const sample = [
{ id: 1, val1: 0, val4: 10 },
{ id: 10, val1: 1, val4: 10, val19: 0, val29: 0 },
{ id: 11, val1: 0, val4: 0, val19: 0, val29: 10 },
];
Run Code Online (Sandbox Code Playgroud)
我想将每个 0 值更改为 null
const sample = [
{ id: 1, val1: null, val4: 10 },
{ id: 10, val1: 1, val4: 10, val19: null, val29: null },
{ id: 11, val1: null, any: null, sample: null, val29: 10 },
];
Run Code Online (Sandbox Code Playgroud)
我知道我需要使用, …
我有这个初始数组:
const initialData = [
{
day: 1,
values: [
{
name: 'Roger',
score: 90,
},
{
name: 'Kevin',
score: 88,
},
{
name: 'Steve',
score: 80,
},
],
},
{
day: 2,
values: [
{
name: 'Roger',
score: 70,
},
{
name: 'Michael',
score: 88,
},
],
},
{
day: 3,
values: [
{
name: 'Steve',
score: 97,
},
],
},
];
Run Code Online (Sandbox Code Playgroud)
要转换为:
const result = [
{
name: 'Roger',
scores: [90, 70, null],
},
{
name: 'Kevin',
scores: …Run Code Online (Sandbox Code Playgroud) 例如我有这样的声明:
场景一:
const ComponentA = lazy(() => import('pages/ComponentA'));
const ComponentB = lazy(() => import('pages/ComponentB'));
<Router>
<Switch>
<Suspense fallback={'loading...'}>
<Route path="/A" component={ComponentA} exact/>
<Route path="/B" component={ComponentB} exact/>
</Suspense>
</Switch>
</Router>
Run Code Online (Sandbox Code Playgroud)
如果 的加载依赖性仅为ComponentA1,则这种情况就很好。
但对于场景 2:如果我有多重依赖怎么办ComponentA?
代码2
import Dependency1 from 'component/dependency1';
import Dependency2 from 'component/dependency2';
const ComponentA = () => {
return (
<div>
<Dependency1/>
<Dependency2/>
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
可以将每个依赖项的 Suspense 声明分开吗?像这样:
代码3
const Dependency1 = lazy(() => import('component/dependency1'));
const Dependency2 = lazy(() => import('component/dependency2'));
const ComponentA = () …Run Code Online (Sandbox Code Playgroud) javascript ×7
typescript ×5
reactjs ×4
ecmascript-6 ×2
html5 ×2
jquery ×2
react-hooks ×2
axios ×1
c# ×1
canvas ×1
html5-canvas ×1
math ×1
parsing ×1
react-redux ×1
redux ×1
string ×1