我正在编写一个React.js应用程序,我想在其中使用Linkreact-router 包中的组件,以便有条件地将用户重定向到另一个页面。如果某些条件不成立,我将to道具设置为空字符串,该字符串有效并且不会导致页面重新加载并且页面保持在与原来完全相同的位置。但我想知道这是否是最佳实践?
这是我的解决方案:
import { Link } from 'react-router';
<Link to={condition === true ? '/some/other/url' : ''}>
<div>
my content
</div>
</Link>
Run Code Online (Sandbox Code Playgroud)
我在文档中没有看到有关空字符串输入的任何内容。
我使用 mongodb 和 graphql-compose-mongoose 来生成 Graphql 模式。不过,我正在添加身份验证突变,并且我想为其中一个查询添加 graphql 输入。我在文档中看到args.filter可以接收输入:
CityTC.addResolver({
kind: 'query',
name: 'findMany',
args: {
filter: `input CityFilterInput {
code: String!
}`,
limit: {
type: 'Int',
defaultValue: 20,
},
skip: 'Int',
// ... other args if needed
},
type: [CityTC], // array of cities
resolve: async ({ args, context }) => {
return context.someCityDB
.findMany(args.filter)
.limit(args.limit)
.skip(args.skip);
},
});
Run Code Online (Sandbox Code Playgroud)
不过我没有使用任何过滤器。我想创建一个像这样的输入:
const AuthPayloadTC = schemaComposer.createObjectTC({
name: 'AuthPayloadTC',
fields: {
jwtToken: 'String!'
}
});
AuthPayloadTC.addResolver({
name: 'userConnectData',
type: AuthPayloadTC, …Run Code Online (Sandbox Code Playgroud) 我是Javascript中解构和可选链提议的忠实粉丝。
我不禁感到,在解构 null 或 undefined 值时,如果结果未定义,因为它在可选链中而不是抛出错误,那将非常有用。
例如:
const person = null
console.log(person?.age) // undefined
Run Code Online (Sandbox Code Playgroud)
然而:
const person = null
const { age } = person // runtime error
Run Code Online (Sandbox Code Playgroud)
它当然不会像这样工作,但是是否有一些 Babel 建议添加此功能?有什么解决方法吗?
我正在做一个 Spring Boot 2.1.6 项目。
ScheduledTasks当我有一个自动装配的对象时,我有一个类db,它允许我访问jdbcTemplate,以便我可以执行查询。start当我从另一个文件的 main调用时,该db对象为空。如果我将该start方法直接放在主类中db则不为空。
我不确定问题是什么。我放置@Component注释,ScheduledTasks以便 Spring 知道我的自动装配对象。我缺少什么?
这是我的ScheduledTasks:
@Component
public class ScheduledTasks {
private Logger log = VastLogger.getLogger(TrackingEventController.class);
@Autowired
private DBHandler db;
public void start() {
if (db == null) {
log.info("db is null from parent");
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的主要课程:
@SpringBootApplication
@EnableJms
public class ServerMain implements CommandLineRunner {
private static final Logger log = LogManager.getLogger(ServerMain.class);
@Autowired
private DBHandler …Run Code Online (Sandbox Code Playgroud) javascript ×3
autowired ×1
graphql ×1
java ×1
nullable ×1
react-router ×1
reactjs ×1
spring ×1
spring-boot ×1